c# 定义operator运算符
2021-04-07 09:25
标签:div IV eth turn str equal get func equals c# 定义operator运算符 标签:div IV eth turn str equal get func equals 原文地址:https://www.cnblogs.com/hnzheng/p/9114131.html 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();
//}
}
}