FileStream to byte[] C#

We just created the byte array. here is the code below

Read(Byte[], Int32, Int32)

Reads a block of bytes from the stream and writes the data in a given buffer.


When this method returns, contains the specified byte array with the values between offset and (offset + count – 1) replaced by the bytes read from the current source.

The byte offset in array at which the read bytes will be placed.

The maximum number of bytes to read.

The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.

Example in WPF with high performance

Reading and recording files
FileStream provides access to files at the byte level, so, for example, if you have to count or write one or more lines into a text file, the array of bytes should be converted into strings using special methods. That’s why other classes are used to work with text files.

At the same time, when dealing with different binary files that have a specific structure, FileStream can be very useful for extracting certain portions of information and processing it.

Let’s look at the example of reading-record in a text file: