E
E-John
Guest
Dear All,
How to use array in struct? I have got null for byte array[] Name in StructA.
Thanks and Best regards,
E-John
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct StructA
{
public UInt16 Index;
public UInt16 Type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
public byte[] Name;
}
static void Main(string[] args)
{
StructA a = new StructA();
for (int i = 0; i < a.Name.Length; i++)
{
a.Name = (byte)i;
}
for (int i = 0; i < a.Name.Length; i++)
{
Console.WriteLine(a.Name);
}
Console.ReadLine();
}
Continue reading...
How to use array in struct? I have got null for byte array[] Name in StructA.
Thanks and Best regards,
E-John
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct StructA
{
public UInt16 Index;
public UInt16 Type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
public byte[] Name;
}
static void Main(string[] args)
{
StructA a = new StructA();
for (int i = 0; i < a.Name.Length; i++)
{
a.Name = (byte)i;
}
for (int i = 0; i < a.Name.Length; i++)
{
Console.WriteLine(a.Name);
}
Console.ReadLine();
}
Continue reading...