To read the first line of a .txt file in a wpf application, we can use this line of code:
string line1 = File.ReadLines("MyFile.txt").First(); // gets the first line
But now, how could i read just the second line of my file?
To read the first line of a .txt file in a wpf application, we can use this line of code:
string line1 = File.ReadLines("MyFile.txt").First(); // gets the first line
But now, how could i read just the second line of my file?
Use Skip(1)
to read the second line. Use FirstOrDefault()
to avoid an error when the file is empty, or has only one line:
var line2 = File.ReadLines("MyFile.txt").Skip(1).FirstOrDefault();