Position Property
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

MemoryStream.Position Property

Gets or sets the current position within the stream.

[Visual Basic]
Overrides Public Property Position As Long
[C#]
public override long Position {get; set;}
[C++]
public: __property __int64 get_Position();
public: __property void set_Position(__int64);
[JScript]
public override function get Position() : long;
public override function set Position(long);

Property Value

The current position within the stream.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException The position is set to a negative value or a value greater than MaxValue.
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:
© 2016 Microsoft