By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,715 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

byte[] and DWord

P: n/a
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?
Dec 7 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
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?

Dec 7 '05 #2

P: n/a
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"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
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?

Dec 7 '05 #3

P: n/a
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" <po******@hotmail.com> wrote in message
news:eO***************@tk2msftngp13.phx.gbl...
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"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
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?


Dec 7 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.