Home
Map
Int16, Int32 and Int64 TypesReview the Int16, Int32 and Int64 types. These types are known as short, int and long.
C#
This page was last reviewed on Oct 11, 2023.
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.
Compiled programs. 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).
short, ushort
int, uint
long, ulong
Type details. 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
An example. 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.
Next The program's output shows that 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
Discussion. 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.
Tip In methods where you use int variables, it is a poor choice to use Int32 variables instead, as int is standard.
Detail For the most readable programs, the int type is usually preferred over the Int32 types.
A summary. 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.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Oct 11, 2023 (edit).
Home
Changes
© 2007-2024 Sam Allen.