void Main()
{
S1 s1 = new S1("hello");
S1 s2 = new S1("hello");
(s1 == s2).Dump();
(s1.Equals(s2)).Dump();
(s1.GetHashCode() == s2.GetHashCode()).Dump();
}
class S1
{
string _name;
public S1(string name)
{
_name = name;
}
public override string ToString()
{
return _name??"";
}
public override bool Equals(object x)
{
"Equals Called".Dump();
return _name.Equals(x.ToString());
}
public static bool operator ==(S1 s1,S1 s2)
{
if (s1._name == s2._name)
return true;
else
return false;
}
public static bool operator !=(S1 s1, S1 s2)
{
if (s1._name != s2._name)
return false;
else
return true;
}
}
// Define other methods and classes here
Showing posts with label dummies. Show all posts
Showing posts with label dummies. Show all posts
Tuesday, December 8, 2009
Operator Overloading, Method Overriding Exampl
Learn as you go - C# developer
Tired from creating projects for testing and learning C#, Try brand new Linq Pad for your C# learning Practice.
Download From: http://www.linqpad.net/
Download From: http://www.linqpad.net/
Subscribe to:
Posts (Atom)