Refresh I would advise you to go with Tim Schmelter's decision .
When you call ReadLine , it moves the cursor to the next line. So, in the second call, you will read the 2nd line.
string Location; using(var reader = new StreamReader("SourceSettings.txt")) { Location = reader.ReadLine();
Do not forget about using .
Or an example of how to do this with the vi ReadLines of the File class if you only need one line from the file. But the solution with ElementAtOrDefault is the best like Tim Schmelter .
var Text = File.ReadLines(@"C:\Projects\info.txt").Skip(1).First()
The ReadLines and ReadAllLines methods differ as follows: when you use ReadLines, you can start enumerating a collection of strings before the entire collection is returned; when you use ReadAllLines, you must wait until the entire array of strings is returned before you can access the array. Therefore, when you work with very large files, ReadLines may be more efficient.
Thus, it does not read all the lines in memory compared to ReadAllLines .
source share