NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

sizeof

[This is preliminary documentation and subject to change]

The sizeof operator is used to obtain the size in bytes for a value type. A sizeof expression takes the form:

sizeof(type)

where:

type
The value type for which the size is obtained.

Remarks

The sizeof operator can be applied only to value types, not reference types.

The sizeof operator can only be used in the unsafe mode. That is, in an unsafe member or inside an unsafe block.

The sizeof operator cannot be overloaded.

Example

// Using the sizeof operator
using System;
class SizeClass {
   // Notice the unsafe declaration of the method:
   unsafe public static void SizesOf() {
      Console.WriteLine("The size of short is {0}.", sizeof(short));
      Console.WriteLine("The size of int is {0}.", sizeof(int));
      Console.WriteLine("The size of long is {0}.", sizeof(long));
   }
}
class MainClass {
   public static void Main() {
   SizeClass.SizesOf();
   }
}

Output

The size of short is 2.
The size of int is 4.
The size of long is 8.

See Also

C# Keywords | Operator Keywords