471,319 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

byte[] and DWord

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
3 5997
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
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
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.

Similar topics

16 posts views Thread by Khuong Dinh Pham | last post: by
4 posts views Thread by Shashi | last post: by
3 posts views Thread by Dennis | last post: by
3 posts views Thread by lovesehuang | last post: by
10 posts views Thread by Chunekit Pong | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.