Int16
, Int32
, Int64
The Int16
, Int32
and Int64
types are aliased to keywords. Typically C# programmers prefer the C-style numeric types, which are easier to read.
When a C# program is compiled, the int
type is the same thing as the Int32
type. So int
is a form of syntactic sugar (which makes the program easier to read).
We show the Int16
, Int32
, and Int64
types are equivalent to more commonly used types. These represent numbers with 2, 4 or 8 bytes.
Int16 -> short Int32 -> int Int64 -> long
We declare Int16
, Int32
and Int64
variables. We print the Type object corresponding to them. Then we do the same thing for the short
, int
and long types.
Int16
is equal to short
, Int32
is equal to int
, and Int64
is equal to long in the runtime.using System; { Int16 a = 1; Int32 b = 1; Int64 c = 1; Console.WriteLine(a.GetType()); Console.WriteLine(b.GetType()); Console.WriteLine(c.GetType()); } { short a = 1; int b = 1; long c = 1; Console.WriteLine(a.GetType()); Console.WriteLine(b.GetType()); Console.WriteLine(c.GetType()); }System.Int16 System.Int32 System.Int64 System.Int16 System.Int32 System.Int64
Should you prefer Int16
to short
, Int32
to int
, or Int64
to long? In programs where the number of bytes is important, you might prefer Int16
, Int32
or Int64
.
int
variables, it is a poor choice to use Int32
variables instead, as int
is standard.int
type is usually preferred over the Int32
types.Int16
, Int32
and Int64
are important. The short
, int
and long types are aliased to them. Programs that specify short
, int
and long are using Int16
, Int32
and Int64
.