CSharp - Data Types Numeric Types

Introduction

C# has the predefined numeric types.

There are three types of predefined numeric types.

  • signed Integral
  • unsigned Integral
  • real number, number with decimal parts

Predefined Integral-signed numeric types in C#

C# type System type SuffixSize Range
sbyteSByte No Suffix 8 bits-2^7 to 2^7 -1
shortInt16 No Suffix 16 bits-2^15 to 2^15-1
int Int32 No Suffix 32 bits-2^31 to 2^31-1
long Int64 L64 bits-2^63 to 2^63-1

Predefined Integral-unsigned numeric types in C#

C# type System type SuffixSize Range
byte ByteNo Suffix 8 bits 0 to 2^8 -1
ushort UInt16 No Suffix 16 bits0 to 2^16-1
uint UInt32 U 32 bits 0 to 2^32-1
ulongUInt64 UL 64 bits 0 to 2^64-1

Predefined real numeric types in C#

C# type System type SuffixSize Range
floatSingle F 32 bits+/- (~10^-45 to 10^38)
double Double D64 bits +/- (~10^-324 to 10^308)
decimal Decimal M 128 bits +/- (~10^-28 to 10^28)

Exercise