Initializing Byte array

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
 
C

Cor

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
 
H

Herfried K. Wagner [MVP]

* "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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top