Why am I not able to Move to the Begin of Stream using the Seek() Method in StreamReader?

As you use StreamReader to manipulate Text files and read one line at a time using Readline() Method you might come across a situation where you are somewhere in the middle of the Stream say on the 5th line and want to go back to the begin of the Stream. You can do that using the Seek Method on the BaseStream of the StreamReader as in this example.

 
using (StreamReader r = new StreamReader(inputFileName))
      {
            r.ReadLine();
            r.BaseStream.Seek(0, SeekOrigin.Begin);
      }
 
 
But there is a problem as you use the Seek Method to go to the Begin of Stream. You use it as shown above, but it still doesn’t seem to move to the Begin of Stream but just continues from the current position. The Reason is it is reading from the Buffered Data, so you need to clear the Buffered data so that the Stream is reloaded and then it goes to the Begin of Stream. Now the Seek Method works fine and goes to the begin of stream.
 
Here is an example how to clear the buffered data.
 
using (StreamReader r = new StreamReader(inputFileName))
      {
            r.DiscardBufferedData();
            r.ReadLine();
            r.BaseStream.Seek(0, SeekOrigin.Begin);
      }