Initializing Byte array

  • Thread starter Thread starter Denis C
  • Start date Start date
D

Denis C

Hi,

Newbie here wondering how to initialize a byte array.
I'm working on the compact framework, and I keep getting
an error because the byte array is null.

Here is the code:

Dim ptr As IntPtr = DBAccessFuncDecl.GetLongVal()
Dim sval As String
Dim lval As Long

Dim size As Integer = 30 + 16

Dim bData As Byte()

***Marshal.Copy(ptr, bData, 0, size)*** HERE IS THE ERROR

sval = System.Text.ASCIIEncoding.ASCII.GetString
(bData, 0, 30)
lval = BitConverter.ToInt64(bData, 31)

Console.WriteLine(lval)

I want to put:

Dim bData As Byte() = New Byte(size)

but no luck.

Thanks,

Denis
 
Hi Mattias,

Are you sure of this?
Dim bData(size-1) As Byte
or
Dim bData As New Byte(size-1) {}

The first says
A bytearea of x bytes (so x * 0)
I think that with that is nothing wrong

The second one says something as
An area of new empty objects byte with a lenght of x

I don't think that is good code

What do I see wrong?

Cor
 
* "Cor said:
Are you sure of this?


The first says
A bytearea of x bytes (so x * 0)
I think that with that is nothing wrong

The second one says something as
An area of new empty objects byte with a lenght of x

Hmmm... The latter doesn't work at all...
 
Back
Top