There is a txt file with the following content:

1) бла бла 2) бла бла бла 3) бла бла бла бла 

I need to write to the variable not the entire file, but only the second line. How to do it?

PS: litter for a potentially stupid question, but it is important.

    2 answers 2

     string secondLine = File.ReadLines("MyTextFile.txt").ElementAtOrDefault(1); 
    • If only in using the wrap - Andrew NOP
    • one
    • @AresGod when it encounters an EOF, or if a fault occurs - i.e. in the case of> 2 lines in the file will hang open before finalizing - PashaPash
     string secondLine; using(var reader = new StreamReader("MyTextFile.txt")) { reader.ReadLine(); // чтобы пропустить одну строку secondLine = reader.ReadLine(); // записываем в переменную }