Show/Hide Toolbars

XSharp

he sizeof operator returns the number of bytes occupied by a variable of a given type. The argument to the sizeof operator must be the name of an unmanaged type or a type parameter that is constrained to be an unmanaged type.

 

Syntax

SizeOf( type )

 

Expression

Constant value

sizeof(sbyte)

1

sizeof(byte)

1

sizeof(short)

2

sizeof(word)

2

sizeof(int)

4

sizeof(dword)

4

sizeof(int64)

8

sizeof(uint64)

8

sizeof(char)

2

sizeof(real4)

4

sizeof(real8)

8

sizeof(decimal)

16

sizeof(logic)

1

 

 

For some types the size depends on how the program is running, e.g. in 32 bits mode or 64 bits mode. In that case you may see an error message that the SizeOf operator requires the /unsafe compiler option.

Note

_sizeof() (with a leading underscore and parenthesis) is also supported for compatibility with Visual Objects and is synonymous with sizeof.