2-dimensional array in struct

  • Thread starter Richard Verzijl
  • Start date
R

Richard Verzijl

Hi,
I want a 2-dimensional array in a struct.

In C it looks like:
struct struct1
{
int array1[4][2];
};

In C# I have a 1-dimensional array in a struct that looks like:
[StructLayout(LayoutKind.Sequential)]
public struct struct1
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)] public int array1;
}

But I want a 2-dimensional array in a struct. How can I do this?


Richard
 
N

Nicholas Paldino [.NET/C# MVP]

Richard,

In this case, what you have is the best solution. The reason for this
is that the marshaller can't figure out how to marshal the bytes across the
boundary, because of the number of dimensions. It would work for
one-dimensional arrays, but not multi-dimensional.



Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top