Считывание чисел из файла - C#
Формулировка задачи:
Доброго времени суток!
Как можно реализовать считывание целых чисел из файла?
Я пробовал так делать:
На что консоль выдала 9-значные коды совершенно не моих данных.
static void Main(string[] args)
{
try
{
using (FileStream fs = new FileStream("C:/Users/Ascold/Documents/Visual Studio 2015/Projects/Lab4AM/Lab4AM/file.txt", FileMode.Open, FileAccess.Read))
{
using (BinaryReader r = new BinaryReader(fs))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(r.ReadInt32());
}
}
}
//Console.WriteLine( tree.Display(tree));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}Решение задачи: «Считывание чисел из файла»
textual
Листинг программы
using (StreamReader sr = new StreamReader("file.txt"))
{
string numbers = sr.ReadLine();
foreach (var number in numbers.Split())
{
Console.WriteLine(number);
}
}