In c#, TextReader is a class of System.IO namespace, and it is useful to read a text or sequential series of characters in the file.
Now, we will see how to use the TextReader class in c# to read a text or sequential series of characters in the file with examples.
Following is the example of reading a text or sequential series of characters in a file using the TextReader object in c#.
If you observe the above example, we imported a System.IO namespace to access File & TextReader objects to open and read text from the given file.
When we execute the above example, it will read the text from “Test.txt” file in D drive and return the result as shown below.
If we want to read only the first line of characters from the file, we need to modify the text reading code, as shown below.
This is how we can use TextReader class in c# to read data from the file in file system.