byte[] and DWord

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght, and
the rest would be for the data.......

Please how can I do it?
 
I suppose it's for interop, isn't it?

Well, if it isn't what about:
struct MyStruct
{
public byte dataid;
public uint datasize;
public byte[] data;
}

if it is, what about:
[StructLayout(Layout.Sequential)]
struct MyStruct
{
public byte dataid;
public uint datasize;
[ MarshalAs( UnmanagedType.ByValArray, SizeConst=100)]
public byte[] data;
}

"Diogo Alves - Software Developer"
 
your post is not clear about reqs but here is something out of what I
understand

struct MyStruct
{
byte myByte;
byte[] myAByte;
double myDouble;
}

you might want to give ctors and init the values or can do that after
creating instance of it.

Thx.


"Diogo Alves - Software Developer"
 
addition to that it is a good idea to give properties rather making values
public.
in my example fields are private so you will have to give properties for it.


Pohihihi said:
your post is not clear about reqs but here is something out of what I
understand

struct MyStruct
{
byte myByte;
byte[] myAByte;
double myDouble;
}

you might want to give ctors and init the values or can do that after
creating instance of it.

Thx.


"Diogo Alves - Software Developer"
Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght,
and
the rest would be for the data.......

Please how can I do it?
 
Back
Top