Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
This is a c code. I want to create equivalent code in c#
              Struct
             {

                unsigned char abc[2][8];
		unsigned char efg[2][8];
             }
	How can I declare this in c#?    
       [StructLayout(LayoutKind.Explicit)]
      //[StructLayout(LayoutKind.Sequential)]
     
      public struct test
        {
            [FieldOffset(0)]
            [MarshalAs(UnmanagedType.ByValArray, SizeConst =8)]
            public byte[,] abc;
        }
Can anyone tell Is this declaration is right or not??

Thanks..
Posted

You can
C#
public struct test
{  [FieldOffset(0)]
   [MarshalAs(UnmanagedType.ByValArray, SizeConst =8)]
   static byte[,] abc = new byte[2, 2];
}
 
Share this answer
 
v2
The below seems correct for a byte 2-dimensional array. But you need to initialize this array.
C#
public byte[,] abc;

Refer
1. Multidimensional Arrays (C# Programming Guide)[^]
2. C# - Multidimensional Arrays[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900