H
herobeat
Hi all,
I'm having a hell of a time with declaring a struct to hold some
binary data I'm trying to read from some files on disk. What I would
like to do is something like this:
public struct binHeader
{
public UInt32 Id;
public UInt32 Offset;
public byte[16] MD5Checksum;
}
In addition to the normal numeric stuff, there is a field I need to
read that's a 16-byte checksum. The problem is that when I try to do
this, I get CS0270, Array size cannot be specified in a variable
declaration (try initializing with a 'new' expression).
I'm a bit confused. I need a field that's exactly 16 bytes long
without actually instantiating 16 bytes of memory in the struct
declaration. Surely I don't have to do something silly like:
public byte MD5Checksum01;
public byte MD5Checksum02;
public byte MD5Checksum03;
...
Yes, I know, I could just use a couple of UInt64s, but what if the
field were 1024 bytes long? Would I be stuck declaring UInt64s
instead of bytes as shown above?
What is the best practice for declaring a struct with a byte array
like this?
Thanks for any help and/or advice.
P.S. Whether I use a struct or a class is irrelevant; I get the same
error.
I'm having a hell of a time with declaring a struct to hold some
binary data I'm trying to read from some files on disk. What I would
like to do is something like this:
public struct binHeader
{
public UInt32 Id;
public UInt32 Offset;
public byte[16] MD5Checksum;
}
In addition to the normal numeric stuff, there is a field I need to
read that's a 16-byte checksum. The problem is that when I try to do
this, I get CS0270, Array size cannot be specified in a variable
declaration (try initializing with a 'new' expression).
I'm a bit confused. I need a field that's exactly 16 bytes long
without actually instantiating 16 bytes of memory in the struct
declaration. Surely I don't have to do something silly like:
public byte MD5Checksum01;
public byte MD5Checksum02;
public byte MD5Checksum03;
...
Yes, I know, I could just use a couple of UInt64s, but what if the
field were 1024 bytes long? Would I be stuck declaring UInt64s
instead of bytes as shown above?
What is the best practice for declaring a struct with a byte array
like this?
Thanks for any help and/or advice.
P.S. Whether I use a struct or a class is irrelevant; I get the same
error.