Declaring Data Buffer

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

I'm converting a project from C++ to C#. I need a structure with several
members that will be read from a file as a single block of data. But when I
try the following, I get an error for the data declaration that says "Array
size cannot be specified in variable declaration".

struct BLOCK_BUFF
{
UInt64 nextBlock;
UInt64 length;
byte data[500];
};

Why can't I declare a structure that looks like this, and how can I work
around this? Note that I want the data member memory to be continguous with
the rest of the structure so I can read it from the file at once.

Thanks.
 
I'm converting a project from C++ to C#. I need a structure with several
members that will be read from a file as a single block of data. But when I
try the following, I get an error for the data declaration that says "Array
size cannot be specified in variable declaration".

struct BLOCK_BUFF
{
UInt64 nextBlock;
UInt64 length;
byte data[500];
};

Why can't I declare a structure that looks like this, and how can I work
around this? Note that I want the data member memory to be continguous with
the rest of the structure so I can read it from the file at once.

Thanks.

Maybe this:

struct BlockBuffer
{
UInt64 nextBlock;
UInt64 length;
[marshalAs(UnmanagedType.ByValArray, SizeConst=500)]
byte[] data;
};
 
Back
Top