class Program
{
static void Main(string[] args)
{
Number n1 = new Number { X = 10 };
Number n2 = new Number { X = 20 };
Number n3 = n1 + n2;// +(n1,n2)
Console.WriteLine("{0}+{1}={2}",n1.X,n2.X,n3.X);
int result = n1 + 30;
Console.WriteLine(result);
Console.WriteLine(n1==n2);//False
Console.WriteLine(n1 != n2); //True
}
}
}
class Number
{
public int X { get; set; }
public static Number operator +(Number n1, Number n2)
{
return new Number { X = n1.X + n2.X };
}
public static int operator +(Number n1, int x)
{
return n1.X + x ;
}
public static bool operator ==(Number n1, Number n2)
{
return n1.X == n2.X;
}
public static bool operator !=(Number n1, Number n2)
{
return n1.X != n2.X;
}
why is it good to use that way of writing code?