-1

I've got this code:

      List<string[]> list = File.ReadLines(@"bin\save.dat")
                                .Select(r => r.TrimEnd('#').Split(','))
                                .ToList();

      Console.WriteLine(File.ReadLines(@"bin\save.dat"));

But it keeps returning System.IO.ReadLinesIterator

I've tried other things on the forum but nothing has worked for me.

emeraldXen
  • 41
  • 2
  • 1
    Have you looked through the rest of the methods available in the File class, such as `ReadAllLines()`? – gunr2171 Feb 19 '21 at 22:25
  • _"it keeps returning System.IO.ReadLinesIterator"_ -- because that's the name of the type of the object, and the object doesn't override `ToString()`. You don't want to print the object itself, you want to print its contents. See duplicates for the explanation of what's going on and for examples of how to use `ReadLines()` correctly. – Peter Duniho Feb 19 '21 at 22:43

2 Answers2

0

To display each line to the console, one solution would be to change

Console.WriteLine(File.ReadLines(@"bin\save.dat"));

to

foreach (var line in File.ReadLines(@"bin\save.dat"))
    Console.WriteLine(line);
tehDorf
  • 775
  • 1
  • 11
  • 32
0

try to use StreamReader :

System.IO.StreamReader file = new System.IO.StreamReader(@"bin\save.dat"); 


     

and then if you want to get all lines ,you can loop till the end of file:

string line;
     while((line = file.ReadLine()) != null)
{
  //do something with line
}