Hi All,
I am using System.Runtime. InteropServices; to marshal a structure using Marshal.structu reToPtr().
But to get the size of structure when i get Marshal.sizeOf( ), it gives me improper sizes.
Code:
public struct IDName
{
public ushort Id;
public int IdLen;
}
Static void Main(string[] args)
{
IdName idname = new IdName();
idname.Id = 1;
idname.IdLen = 1;
int size = Marshal.SizeOf( idname);
}
It gives me size as 8 instead of 6 i.e, ushort + int.
If i use only ushort or only int then it shows me proper size.
This problem is coming with byte, sbyte as well.
Plz suggest something to get proper results.
Thanks
Eric
I am using System.Runtime. InteropServices; to marshal a structure using Marshal.structu reToPtr().
But to get the size of structure when i get Marshal.sizeOf( ), it gives me improper sizes.
Code:
public struct IDName
{
public ushort Id;
public int IdLen;
}
Static void Main(string[] args)
{
IdName idname = new IdName();
idname.Id = 1;
idname.IdLen = 1;
int size = Marshal.SizeOf( idname);
}
It gives me size as 8 instead of 6 i.e, ushort + int.
If i use only ushort or only int then it shows me proper size.
This problem is coming with byte, sbyte as well.
Plz suggest something to get proper results.
Thanks
Eric
Comment