In this post we will read a data from a file and store them into a list using ReadAllLines method.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Program { static void Main(string[] args) { // Specifying a file string path = @"E:\file.txt"; // Calling the ReadAllLines() function List<string> readText = new List<string>(File.ReadAllLines(path)); readText.ForEach((line) => Console.WriteLine(line)); ; Console.ReadLine(); } } |
Sample Output:
1 2 3 4 5 | 1;Tom;Garnd 2;Mark;Bard 3;Doe;Joe |