Console.WriteLine ("Please enter some numbers");
int sum = 0;
for(;;)
{
string input = Console.ReadLine ();
if (string.IsNullOrEmpty (input))
{
break;
}
int inputParsed = int.Parse (input.ToString ());
int sumParsed = int.Parse (sum.ToString ());
sum = sum + input; // throws an error here
Console.WriteLine (sum);
I want my programme to show the sum of all numbers entered by user, by even though I have parsed all the variables needed, it throws an "cannot implicitly convert type 'string' to 'int'" error. What's wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…