Stream.Flush Method (System.IO)

Switch View :
ScriptFree
.NET Framework Class Library
Stream.Flush Method

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic
Public MustOverride Sub Flush
C#
public abstract void Flush()
Visual C++
public:
virtual void Flush() abstract
F#
abstract Flush : unit -> unit 

Exceptions

Exception Condition
IOException

An I/O error occurs.

Remarks

Override Flush on streams that implement a buffer. Use this method to move any information from an underlying buffer to its destination, clear the buffer, or both. Depending upon the state of the object, you might have to modify the current position within the stream (for example, if the underlying stream supports seeking). For additional information see CanSeek.

When using the StreamWriter or BinaryWriter class, do not flush the base Stream object. Instead, use the class's Flush or Close method, which makes sure that the data is flushed to the underlying stream first and then written to the file.

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Other Resources

Community Content

VeeruXbox
MemoryStream.Flush()
This is a special case. When your stream is a MemoryStream (a memory backed expandable unsigned byte array), Flush() doesn't make sense. A Flush() will generally clear all the buffers and write the buffered data to the underlying device which here again is Memory. some citiation is needed here as if it is a good idea to dispose the Memorystream and create a new one if you have to use the MemoryStream more than once and dont want to keep appending to the stream??

Junketsu
Must override is because method is abstract
"Override Flush on streams that implement a buffer." $0$0 $0 $0When deriving from Stream, you do not have the option to override it or not because Flush is an abstract method in Stream (so it must be overridden).$0