What is the difference between int and Int32 in C#?

CsharpServer Side ProgrammingProgramming

Int32 is a type provided by .NET framework whereas int is an alias for Int32 in C# language.

  • Int32 x = 5;

  • int x = 5;

So, in use both the above statements will hold a 32bit integer. They compile to the same code, so at execution time there is no difference whatsoever.

The only minor difference is Int32 can be only used with System namespace. While validating the type of a value like mentioned above we can use Int32 or int.

typeof(int) == typeof(Int32) == typeof(System.Int32)

Example

The below example shows how an integer is declared using System.Int32.

 Live Demo

using System;
namespace DemoApplication{
   class Program{
      static void Main(string[] args){
         Int32 x = 5;
         Console.WriteLine(x); //Output: 5
      }
   }
}

Output

5

Example

The below example shows how an integer is declared using int keyword.

 Live Demo

using System;
namespace DemoApplication{
   class Program{
      static void Main(string[] args){
         int x = 5;
         Console.WriteLine(x); //Output: 5
      }
   }
}

Output

5
raja
Published on 04-Aug-2020 06:32:40
Advertisements