Part 12 Difference between int and Int32 in c#

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

This is a very basic and a common c# interview question.

Int32 and int are synonymous, both of them allow us to create a 32 bit integer. int is shorthand notation (alias) for Int32. When declaring an integer in a c# program most of us prefer using int over Int32.

Whether we use int or Int32 to create an integer, the behaviour is indentical.

int i = 10;
Int32 j = 10;

Console.WriteLine(“int i = ” + i);
Console.WriteLine(“Int32 j = ” + j);
Console.WriteLine(“int i + Int32 j = ” + (i + j));

I think the only place where Int32 is not allowed is when creating an enum. The following code will raise a compiler error stating – Type byte, sbyte, short, ushort, int, uint, long, or ulong expected.
enum Test : Int32
XXX = 1

The following code will compile just fine
enum Test : int
XXX = 1

I can think of only the following minor differences between int and Int32
1. One of the difference is in readability. When we use Int32, we are being explicitl about the size of the variable.
2. To use Int32, either we need to use using System declaration or specify the fully qualified name (System.Int32) where as with int it is not required

The interviewer may also ask, what is the difference between string and System.String.
There is no difference string is an alias for System.String.

    .Net abstract abstract class advantage Advantages array arraylist AS benefits block C (Programming Language) C# c# class default constructor access modifier c# interview questions and answers c# reflection constructor access modifier c# reflection constructor not found c# reflection default constructor c# reflection get constructor c# reflection private constructor c# reflection protected constructor call cast catch class constructor csharp Data DataTypes difference between Difference between int and Int32 in c# different directory dot net dotnet Each example exception exceptions factorial files Finally folder frequently asked function generic Handle happens int vs int32 interfaces interview is jagged keyword LINQ list Lists method Number occur Operator Overriding purpose question questions Real Real-time real-world realtime Recursion recursive reverse Sentence single store String Structure subdirectories Throw throws time try Types Use using virtual method what when where Why Word World