using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Int32 a = 3;
Int32 b = 5;
a = Console.Read();
b = Convert.ToInt32(Console.ReadLine());
Int32 a_plus_b = a + b;
Console.WriteLine("a + b =" + a_plus_b.ToString());
}
}
}
我得到的ReadLine()
功能的錯誤消息:Console.Read()和到Console.ReadLine()出現FormatException
出現FormatException了未處理。
什麼問題?
也許你是把該字符串不是有效的整數?嘗試讀取數據到變量,並添加一些驗證使用'TryParse' – wudzik
在哪個特定的行給出這個錯誤,這個變量的值是什麼.. –
如果我評論「a = ...」或「b = .. 。「然後一切都很好。 這些值只是簡單的數字,如4或7. – BlackCat