I have a text file with few hundred lines, the structure is pretty simple.
firstname lastname
I need to pick out a random firstname & listname from the file.
string[] lines = File.ReadAllLines(...); //i hope that the file is not too big Random rand = new Random(); return lines[rand.Next(lines.Length)];
Another (and maybe better) option is to have the first line of the file contain the number of records in it and then you don't have to read all the file.
2.1m questions
2.1m answers
60 comments
57.0k users