Numeric Types
C# has the following predefined numeric types.
C# type |
System type |
Suffix |
Size |
Range |
---|---|---|---|---|
Integralâsigned | Â | Â | Â | |
|
| Â |
|
|
|
| Â |
|
|
|
| Â |
|
|
|
|
|
|
|
Integralâunsigned | Â | Â | Â | |
|
| Â |
|
|
|
| Â |
|
|
|
|
|
|
|
|
|
|
|
|
Real | Â | Â | Â | Â |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Of the integral types, int
and
long
are first-class citizens and C# and the runtime
favor both. The other integral types are typically used for interoperability or when space
efficiency is paramount.
Of the real number types, float
and double
are called floating-point
types and are typically used for scientific calculations. The decimal
type is typically used for financial calculations, where
base-10-accurate arithmetic and high precision are required.[1]
Numeric Literals
Integral literals can use decimal or hexadecimal notation;
hexadecimal is denoted with the 0x
; prefix. For
example:
int x = 127; long y = 0x7F;
Real literals can use decimal and/or exponential notation. For example:
double d = 1.5; double million = 1E06;
Numeric literal ...
Get C# 3.0 Pocket Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.