请教一个连续加法的问题?
要求是一个控制台程序或者是form含有多行文本框 实现依次输入数字(个数不限制)每行一个数据 enter 实现数据换行 当发现用户输入 = 号时候 输出所有输入的数据的总和 这个循环应该怎么写?
2010-03-31 17:31
程序代码:class Program
{
static void Main(string[] args)
{
int sum = 0;
List<int> L = new List<int>();
Action<int> Show = delegate(int intToAdd)
{
sum += intToAdd;
};
while (true)
{
string s = Console.ReadLine();
if (s == "=")
{
L.ForEach(Show);
Console.WriteLine("sum=" + sum.ToString());
sum = 0;
L.Clear();
}
else if (s != "")
{
L.Add(int.Parse(s));
}
}
Console.ReadLine();
}
}

2010-03-31 19:09
2010-03-31 19:55
2010-03-31 19:58
2010-03-31 21:29