How to read entire stream contents?

 Posted by Raja on 9/8/2008 | Category: C# Interview questions | Views: 5821

If you have a stream object (any of the stream like StreamReader, MemoryStream, FileStream) and you want to show its content, write following code.

// here theStream is the stream object

while (myStream.Position != myStream.Length)
Console.WriteLine("{0:x2}", myStream.ReadByte());

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response