c# 定义operator运算符
public void TestFunc() { Complex complex1 = new Complex(); Complex complex2 = new Complex(); var s = complex1 + complex2; } } public class Complex { public string Name { get; set; } public int Age { get; set; } public Complex() { } // 必须在当前类中定义 public static Complex operator +(Complex a, Complex b) { return new Complex() { Name = a.Name + b.Name, Age = a.Age + b.Age }; } public static string operator -(Complex a, Complex b) { return null; } //public static Boolean operator ==(Complex a, Complex b) //{ // return true; //} //public static Boolean operator !=(Complex a, Complex b) //{ // return false; //} //public override bool Equals(object obj) //{ // return base.Equals(obj); //} //public override int GetHashCode() //{ // return base.GetHashCode(); //} } }