8
I have a text file which has more than 3000 lines. I am finding the number of lines using
string[] lines = File.ReadAllLines(myPath);
var lineCount = lines.Length;
Then I am generating a random number
Random rand = new Random();
var lineToRead = rand.Next(1, lineCount);
Now I need to read the specific line that is generated by random number. I can do this using
string requiredLine = lines[lineToRead];
Because my file is big I don't think creating such a big array is efficient. Is there a more efficient or easier way to do this?