Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MemoryStream.Length Property

Gets the length of the stream in bytes.

[Visual Basic]
Overrides Public ReadOnly Property Length As Long
[C#]
public override long Length {get;}
[C++]
public: __property __int64 get_Length();
[JScript]
public override function get Length() : long;

Property Value

The length of the stream in bytes.

Exceptions

Exception Type Condition
ObjectDisposedException The stream is closed.

Remarks

For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the MemoryStream class.

[Visual Basic] 
' Write the stream properties to the console.
Console.WriteLine( _
    "Capacity = {0}, Length = {1}, Position = {2}", _
    memStream.Capacity.ToString(), _
    memStream.Length.ToString(), _
    memStream.Position.ToString())

[C#] 
// Write the stream properties to the console.
Console.WriteLine(
    "Capacity = {0}, Length = {1}, Position = {2}\n",
    memStream.Capacity.ToString(), 
    memStream.Length.ToString(), 
    memStream.Position.ToString());

[C++] 
// Write the stream properties to the console.
Console::WriteLine(S"Capacity = {0}, Length = {1}, "
    S"Position = {2}\n", memStream->Capacity.ToString(), 
    memStream->Length.ToString(), 
    memStream->Position.ToString());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemoryStream Class | MemoryStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2017 Microsoft