In this article, we will learn, how we can read a Text file using C#, To read from file we have two class File and FileInfo which help us to read a text from a file.

The ‘File’ class holds static methods and offers security checks on all the methods. The FileInfo holds instance methods and security check is not needed. For reading from a text file, we have abstract classes like the TextReader class.

public void Read()
{
  //path of file
  var path = @"E:\TheCodeHubs.txt";

  if (System.IO.File.Exists(path))
  {
   using (TextReader tr = new StreamReader(path))
   {
     var text = tr.ReadLine();
   }
  }
}

If you are looking for a write-in a file using c#, you can read from here.