using System.IO; StreamReader reader = new StreamReader("file.txt"); while (!reader.EndOfStream) { string line = reader.ReadLine(); Console.WriteLine(line); } reader.Close();
using System.IO; StreamReader reader = new StreamReader("data.csv"); while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] fields = line.Split(','); // Do something with the fields... } reader.Close();This example shows how to use the C# Reader to read and parse comma-separated value (CSV) data. The `Split()` method is used to split each line of the file into an array of fields, using the comma as a delimiter. Once the fields are extracted, they can be processed in some way. Package library: System.IO Overall, the C# Reader is a powerful tool for reading data from streams in a variety of formats. Its versatility and flexibility make it a cornerstone of file and data processing in C#.