C# 我写一个小计算器的程序,我想定义一个类calculator,把加减乘除写成4个方法,然后在界面调用,求解!

2024-12-21 15:10:06
推荐回答(2个)
回答1:

class Program
{
static void Main(string[] args)
{
calculator a = new calculator();
a.ADD(1, 2);
a.Minus(2, 1);
a.Multiply(2, 2);
a.Except(2, 2);
}
public class calculator
{
public int ADD(int a, int b)
{
return a + b;
}
public int Minus(int a, int b)
{
return a - b;
}
public int Multiply(int a, int b)
{
return a * b;
}
public int Except(int a, int b)
{
return a / b;
}
}
}

回答2:


textbox.text=result.Add(first,second)

修改为
textbox.text=result.Add(first,second).toString();
就行了