using System.Runtime.InteropServices;
public static int getSize(Type type)
return Marshal.SizeOf(Enum.GetUnderlyingType(type));
return Marshal.SizeOf(type);
public static void Main()
Console.WriteLine("{0}", sizeof (int));
Console.WriteLine("{0}", Environment.Is64BitOperatingSystem);
Console.WriteLine("{0}", IntPtr.Size);
Console.WriteLine("{0}", Marshal.SizeOf(a));
Console.WriteLine("{0}", Marshal.SizeOf(b));
Console.WriteLine("{0}", getSize(b.GetType()));