我有一个外部文本文件,其中包含数字。如4 54 12 32由空格分隔。 我希望能够读取所有数字并将它们添加到列表中。从文本文件中读取数字并分隔空格
static void Main(string[] args)
{
List<int> numbers;
numbers = new List<int>();
StreamReader file = new StreamReader("C:\\text.txt");
while (!file.EndOfStream)
{
string line = file.ReadLine();
Console.Write(line + " ");
}
}
的ReadLine读取整个行,所以我不能分开的单独号码,并将其转换为整数,我试图了解它读取每个数字的字符代码,而不是数字本身。