.Net supports many fixed point numeric data type by default.
Mostly we use integers.
Below are all the fixed point numeric data types supported by .net and their corresponding c# data types
You can choose one of these types for you variables and constants depending upon your requirement (range of the data and it can be negative number of not).
.Net Type | C# Type | Size in bytes | Min Value | Max Value | Suffix |
---|---|---|---|---|---|
System.SByte | sbyte | 1 | -128 (-27) |
127 (27-1) |
|
System.Int16 | short | 2 | -32,768 (-215) |
32,767 (215-1) |
|
System.Int32 | int | 4 | -2,147,483,648 (-231) |
2,147,483,647 (231-1) |
|
System.Int64 | long | 8 | -9,223,372,036,854,775,808 (-263) |
9,223,372,036,854,775,807 (263-1) |
L/l |
System.Byte | byte | 1 | 0 | 255 (28-1) |
|
System.UInt16 | ushort | 2 | 0 | 65,535 (216-1) |
|
System.UInt32 | uint | 4 | 0 | 4,294,967,295 (232-1) |
U/u |
System.UInt64 | ulong | 8 | 0 | 18,446,744,073,709,551,615 (264-1) |
UL/ul |
When using a constant number in the program by default it is considered as integer.
If you want to change its type to long or unsigned integer or unsigned long, you can use the suffix
Example.
var len = 245L; // long
var size = 200UL; // unsigned long
var age = 32U; // unsigned integer
No comments:
Post a Comment