In this code you can read a text file line by line to a list collection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Program { static void Main(string[] args) { List<string> myList = new List<string>(); FileStream file = new FileStream(@"C:\test.txt", FileMode.Open, FileAccess.Read); using (var sr = new StreamReader(file, Encoding.UTF8)) { while (sr.Peek() >= 0) { myList.Add(sr.ReadLine()); } } Console.WriteLine("Line Count:{0}", myList.Count); Console.ReadLine(); } } |