To overload the equality operator(=) To overload an operator on a custom class requires creating a method on the class with the correct signature The method must be named operator x"where x is the name or symbol of the operator being overloaded Unary operators have one parameter, and binary operators have two parameters In each case, one parameter must be the same type as the class or struct that declares the operator
To overload the equality operator (==) • To overload an operator on a custom class requires creating a method on the class with the correct signature. • The method must be named "operator X" where X is the name or symbol of the operator being overloaded. • Unary operators have one parameter, and binary operators have two parameters. • In each case, one parameter must be the same type as the class or struct that declares the operator
public override bool Equals(Object o) f ( o is ObjectShap) return false 345678908288888880 ObjectShap S =(ObjectShap)o ze public static bool operator =(ObjectShap sl, Object Shap s2) if (ReferenceEquals(s1, s2)) return true else if (s1. Get Type0!= s2.GetType 0)return false else return sl shape Width = s2 shape. Width & sl shape. Height =s2 shape. height 91 92 oublic static bool operator! =(0bjectShap sl, ObjectShap s2) 93
a CSharp Blank Window 日X
a CSharp Blank Window 日X
a CSharp Blank Window 目X