Reading and writing with streams

A stream is a sequence of bytes.

There is an abstract class named Stream that represents a stream. There are many classes that inherit from this base class, so they all work the same way. In the following table are some of the common members of the Stream class:

Member

Description

CanRead, CanWrite

This determines whether you can read from and write to the stream

Length, Position

This determines the total number of bytes and the current position within the stream

Dispose()

This closes the stream and releases its resources

Flush()

If the stream has a buffer, then it is cleared and written to the underlying stream

Read(), ReadAsync()

This reads a specified number of bytes from the stream into ...

Get C# 7 and .NET Core now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.