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

Determines whether you can read to and write from the stream

Length, Position

Determines the total number of bytes and the current position within the stream

Close()

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()

Reads a specified number of bytes from the stream into a byte array and advances the position ...

Get C# 6 and .NET Core 1.0: Modern Cross-Platform Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.