主题:这个程序怎么会出现这样的结果???
using Systerm;
namespace Calculator
{
class Calculator
{
public int number1,number2;
public Calculator( int num1,int num2)
{
number1=num1;
number2=num2;
}
public static Calculator operator -(Calculator c1)
{
c1.number1=-c1.number1;
c1.number2=-c1.number2;
return c1;
}
public void Print()
{
Console.WriteLine(" number1=" +number1);
Console.WriteLine(" number2=" +number2);
Console.ReadLine();
}
}
class EnterPoint
{
static void Main()
{
Calculator calc = new Calculator(15,-25);
calc=-calc;
calc.Print();
}
}
}
输出
number1=-15
number2=25
这是关于运算符重载的问题 我一直没有弄的懂 拜托帮我解释一下这个程序的运行过程[color=FF0000]-15 25[/color]
namespace Calculator
{
class Calculator
{
public int number1,number2;
public Calculator( int num1,int num2)
{
number1=num1;
number2=num2;
}
public static Calculator operator -(Calculator c1)
{
c1.number1=-c1.number1;
c1.number2=-c1.number2;
return c1;
}
public void Print()
{
Console.WriteLine(" number1=" +number1);
Console.WriteLine(" number2=" +number2);
Console.ReadLine();
}
}
class EnterPoint
{
static void Main()
{
Calculator calc = new Calculator(15,-25);
calc=-calc;
calc.Print();
}
}
}
输出
number1=-15
number2=25
这是关于运算符重载的问题 我一直没有弄的懂 拜托帮我解释一下这个程序的运行过程[color=FF0000]-15 25[/color]