Mega Code Archive

 
Categories / C# / Language Basics
 

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();     } }