This documentation is archived and is not being maintained.

Buffer.ByteLength Method

Returns the number of bytes in the specified array.

[Visual Basic]
Public Shared Function ByteLength( _
   ByVal array As Array _
) As Integer
[C#]
public static int ByteLength(
 Array array
);
[C++]
public: static int ByteLength(
 Array* array
);
[JScript]
public static function ByteLength(
   array : Array
) : int;

Parameters

array
An array.

Return Value

The number of bytes in the array.

Exceptions

Exception Type Condition
ArgumentNullException array is a null reference (Nothing in Visual Basic).
ArgumentException array is not a primitive.

Example

[Visual Basic] 
Dim arr() As Integer = {0, 1, 2, 3, 4}
Debug.Assert(Buffer.ByteLength(arr) = 20)
Dim i As Integer
For i = 0 To Buffer.ByteLength(arr) - 1
    Console.Write(arr(i))
Next i

'This will print: 00000001000200030004

[C#] 
int [] arr = new int [5] {0, 1, 2, 3, 4};
Debug.Assert (Buffer.ByteLength(arr) == 20);
for (int i = 0; i < Buffer.ByteLength(arr); i++)
  {
  Console.Write(arr[i]);
  }
//This will print: 00000001000200030004

[C++] 
Int32 arr[] = {0, 1, 2, 3, 4};
Debug::Assert (Buffer::ByteLength(arr) == 20);
for (int i = 0; i < Buffer::ByteLength(arr); i++)
  {
  Console::Write(arr[i]);
  }
//This will print: 00000001000200030004

[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

See Also

Buffer Class | Buffer Members | System Namespace

Show: