You must declare that code that uses the sizeof operator as unsafe. : sizeof « Language Basics « C# / C Sharp






You must declare that code that uses the sizeof operator as unsafe.

  
class SomeClass
{
    static unsafe public void ShowSizes() 
    {
        Console.WriteLine("\nBasic type sizes");
        Console.WriteLine("sizeof short = {0}", sizeof(short));
        Console.WriteLine("sizeof int = {0}", sizeof(int));
        Console.WriteLine("sizeof long = {0}", sizeof(long));
        Console.WriteLine("sizeof bool = {0}", sizeof(bool));
    }
}
   
class SizeofBasicTypesApp
{
    unsafe public static void Main(string[] args) 
    {
        SomeClass.ShowSizes();
    }
}

   
  








Related examples in the same category

1.check size with sizeof operator