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 override. Show all posts
Showing posts with label override. Show all posts
Tuesday, December 8, 2009
Operator Overloading, Method Overriding Exampl
Subscribe to:
Posts (Atom)