June 19, 2015

Practically there are no differences between int and System.Int32 (except while using enums). C# allows for certain aliases and it is one of those. Both int and System.Int32 are compiled to System.Int32 in the Intermediate Language (IL). C# contains a number of aliases that allows for quick typing of the variable types. Here is a full list of the aliases.

object:  System.Object
string: System.String
bool: System.Boolean
byte: System.Byte
sbyte: System.SByte
short: System.Int16
ushort: System.UInt16
int: System.Int32
uint: System.UInt32
long: System.Int64
ulong: System.UInt64
float: System.Single
double: System.Double
decimal: System.Decimal
char: System.Char

One difference between aliases and full name though arise during the use of enums. Enum expects to have the alias instead of the full name and does not compile when full name is provided.






  1. public enum Test1 : int { sun=1, mon=2};//compiles

  2. public enum Test2 : System.Int32 { sun = 1, mon = 2 };//error




0 comments:

Reference: Shahed Kazi at AspNetify.com