sizeof C# with Example
Returns an int holding the size of a type* in bytes. sizeof(bool) // Returns 1. // Returns 1. sizeof(byte) sizeof(sbyte) // Returns 1. // Returns 2. sizeof(char) // Returns 2. sizeof(short) // Returns 2. sizeof(ushort) // Returns 4. sizeof(int) // Returns 4. sizeof(uint) // Returns 4. sizeof(float) sizeof(long) // Returns 8. // Returns 8. sizeof(ulong) // Returns 8. sizeof(double) sizeof(decimal) // Returns 16. *Only supports certain primitive types in safe context. In an unsafe context, sizeof can be used to return the size of other primitive types and structs. public struct CustomType { public int value; } static void Main() { unsafe { Console.WriteLine(sizeof(CustomType)); // outputs: 4 } }