C# TextReader
Found in System.IO namespace, the C# TextReader class is used as a reader for reading text or sequential series of characters.
Example:
using System; using System.IO; namespace Example { class content { static void Main(string[] args) { using (TextReader reader = File.OpenText("d:\\file.txt")) { Console.WriteLine(reader.ReadToEnd()); } } } } |
Output:
Explanation:
In the above example, we are using the TextReader class to read all the data of a file.
Example:
using System; using System.IO; namespace Example { class content { static void Main(string[] args) { using (TextReader reader = File.OpenText("d:\\file.txt")) { Console.WriteLine(reader.ReadLine()); } } } } |
Output:
Explanation:
In the above example, we are using the TextReader class to read a single line from a file.