Cannot implicitly convert type string to int

前端 未结 4 1250
囚心锁ツ
囚心锁ツ 2020-12-21 16:34
    Console.WriteLine (\"Please enter some numbers\");
        int sum = 0;
        for(;;)
        {
            string input = Console.ReadLine ();
            if          


        
4条回答
  •  攒了一身酷
    2020-12-21 17:28

    sum = sum + input; //throws an error here
    

    should be:

    sum = sum + inputParsed ;
    

    You are using the original input instead of the parsed value. And you don't need sumParsed because you just keep the total sum in sum and you do no need to cast the int to a string and then parse it back to an integer.

提交回复
热议问题