Articles → CSHARP → Data Types In C#
Data Types In C#
Signed And Unsigned Numbers
Boolean
Boolean x = false;
bool y = false;
Byte And Sbyte
- In computers, information is stored in the form of bits
- A bit is the smallest unit of information
- A bit is a single numeric value that is either ‘0’ or ‘1’
- A Byte is a sequence of bits
- 8 bits make 1 byte
Data Type | Minimum Value | Maximum Value |
---|
byte | 0 | 255 |
sbyte | -128 | 127 |
byte unsignedByte = 240;
sbyte signedByte = -120;
Char
char x = 'A'; // Single character
char y = '\u0041'; // Unicode of 'A'
Data Type | Minimum Value | Maximum Value |
---|
char | '\u0000' | '\uffff' |
Int, Long, Short, Uint, Ulong And Ushort
Data Type | Minimum Value | Maximum Value |
---|
int | -2,147,483,648 | 2,147,483,647 |
long | -923,372,036,854,775,808 | 9,223,372,036,854,775,807 |
short | -32,768 | 32,767 |
uint | 0 | 4,294,967,295 |
ulong | 0 | 18,446,744,073,709,551,615 |
ushort | 0 | 65535 |
int a;
long b;
short c;
uint d;
ulong e;
ushort f;
Decimal, Double, And Float
Data Type | Size | Precision |
---|
float | 32-bit | 7 significant digits |
double | 64-bit | 15-16 significant digits |
decimal | 128-bit | 28-29 significant digits |
- All non-zero digits are significant digits
- Zero among the non-zero digits is a significant digit
- All leading zeros before decimal are non-significant
- All zeros after decimal are significant digits
- 12 contain 2 significant digits
- 7000 contains 1 significant digit
- 4009 contains 4 significant digits
- 4.20 contains 3 significant digits
decimal a = 0.0M;
float b = 0.0F;
double c = 0.0;