With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Numeric Types

C# has the following predefined numeric types:

C# type

System type

Suffix

Size

Range

Integral—signed

`sbyte`

`SByte`

8 bits

–27 to 27–1

`short`

`Int16`

16 bits

–215 to 215–1

`int`

`Int32`

32 bits

–231 to 231–1

`long`

`Int64`

`L`

64 bits

–263 to 263–1

Integral—unsigned

`byte`

`Byte`

8 bits

0 to 28–1

`ushort`

`UInt16`

16 bits

0 to 216–1

`uint`

`UInt32`

`U`

32 bits

0 to 232–1

`ulong`

`UInt64`

`UL`

64 bits

0 to 264–1

Real

`float`

`Single`

`F`

32 bits

± (~10–45 to 1038)

`double`

`Double`

`D`

64 bits

± (~10–324 to 10308)

`decimal`

`Decimal`

`M`

128 bits

± (~10–28 to 1028)

Of the integral types, `int` and `long` are first-class citizens and are favored by both C# and the runtime. 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. (Technically, `decimal` is a floating-point type too, although it’s not generally referred to as such.)

Numeric Literals

Integral literals can use decimal or hexadecimal notation; hexadecimal is denoted with the `0x` prefix (e.g., `0x7f` is equivalent to `127`). Real literals may use decimal or exponential notation such as `1E06`.

Numeric literal type inference

By default, the compiler infers a numeric literal to be either `double` or an integral type:

• If the literal contains a decimal point or the exponential symbol (`E`), it is a `double`.

• Otherwise, the literal’s type is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required