class Salary{
public Salary(int val){
this.val = val;
}
public int val
{
private set;
get;
}
override public string ToString()
{
return val.ToString();
}
<font color=blue>
static public Salary operator +(Salary a, Salary b){
return new Salary(a.val + b.val);
}
static public Salary operator -(Salary a, Salary b){
return new Salary(a.val - b.val);
}
</font>
}
Salary s1 = new Salary(1);
Salary s2 = new Salary(2);
Salary r1 = s1 + s2; // 3
Salary r2 = s1 - s2; // -1
网友评论