Why does char take 1 byte in Marshal.SizeOf while bool takes 4 bytes. Doesn’t char has more states than a bool
char c = '\x0011';
bool b = true;
Console.WriteLine("char: " + Marshal.SizeOf(c).ToString() + "\n"
+ "bool: " + Marshal.SizeOf(b).ToString());
//char: 1
//bool: 4
You are looking at what the Marshal class makes of it. Try this to see what the compiler thinks:
Applying
Marshal.SizeOf()to local variables isn’t the intended use. The basic idea is that you create astructfor interop and then the concept of padding becomes relevant.