Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An array of array of bytes in VB.NET

Tags:

arrays

vb.net

I need an array and each item in the array is an array of bytes like this, but I'm not sure how to do the:

Dim xx as array

xx(0) *as byte* = {&H12, &HFF}

xx(1) *as byte* = {&H45, &HFE}
like image 351
Jonathan. Avatar asked Dec 31 '09 22:12

Jonathan.


People also ask

What is array of array in VB?

An array is a linear data structure that is a collection of data elements of the same type stored on a contiguous memory location. Each data item is called an element of the array.

What is an array of byte?

A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..

What is array in VB net with example?

An array is a set of values, which are termed elements, that are logically related to each other. For example, an array may consist of the number of students in each grade in a grammar school; each element of the array is the number of students in a single grade.

What is byte in VB net?

The Byte data type widens to Short , UShort , Integer , UInteger , Long , ULong , Decimal , Single , or Double . This means you can convert Byte to any of these types without encountering a System.


2 Answers

You can make a nested or "jagged" byte array like this:

Dim myBytes(6)() As Byte

This will create an empty array of 6 byte arrays. Each element in the outer array will be Nothing until you assign an array to it, like this:

 myBytes(0) = New Byte() { &H12, &Hff }

However, it would probably be a better idea to make a List of byte arrays, like this:

Dim myBytes As New List(Of Byte())

This will create an empty list of byte array, which will stay empty until you put some byte arrays into it, like this:

myBytes.Add(New Byte() { &H12, &Hff })

Unlike the nested array, a List(Of Byte()) will automatically expand to hold as many byte arrays as you put into it.

For more specific advice, please tell us what you're trying to do.

like image 67
SLaks Avatar answered Oct 12 '22 23:10

SLaks


Please refer to this MSDN topic for more details.

Here's the code to define a multidimensional array:

Dim lotsaBytes(2,4) As Byte

And to initialize it:

Dim lotsaBytes(,) As Byte = New Byte(2, 4) {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
like image 40
Eilon Avatar answered Oct 13 '22 00:10

Eilon