输出控制台两个数字的总和

时间:2014-04-18 02:18:13

标签: c# console

我试图得到两个数字的总和,但它没有正确显示。这是代码:

int number1 = 1;
int number2 = 3;

Console.Write("The sum of " number1 "and" number2 "is" total ".");

2 个答案:

答案 0 :(得分:6)

试试这个:

Console.Write("The sum of {0} and {1} is {2}.", number1, number2, total); 

答案 1 :(得分:2)

试试这个:

Console.Write("The sum of " + number1 + " and " + number2 + " is " + total +".");

您需要+运算符将字符串连接在一起。