Windows apps
Collapse the table of content
Expand the table of content

WindowsRuntimeBufferExtensions.ToArray Method (IBuffer, UInt32, Int32)

.NET Framework (current version)

Returns a new array that is created from the contents of the specified buffer (Windows.Storage.Streams.IBuffer), starting at a specified offset and including a specified number of bytes.

This API is not CLS-compliant. 

Namespace:  System.Runtime.InteropServices.WindowsRuntime
Assembly:  System.Runtime.WindowsRuntime (in System.Runtime.WindowsRuntime.dll)

public static byte[] ToArray(
	this IBuffer source,
	uint sourceIndex,
	int count


Type: IBuffer

The buffer whose contents populate the new array.

Type: System.UInt32

The index in source to begin copying data from.

Type: System.Int32

The number of bytes to copy.

Return Value

Type: System.Byte[]
A byte array that contains the specified range of bytes.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IBuffer. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).


source is null.


count or sourceIndex is less than 0 (zero).


sourceIndex is greater than or equal to the capacity of source.


The number of bytes in source, beginning at sourceIndex, is less than count.

.NET Framework

Supported in: 4.6, 4.5

.NET for Windows Phone apps

Supported in: Windows Phone Silverlight 8
© 2017 Microsoft