Loading lessons...
Cheatsheet: Common Types & Converters
Cheatsheet: Common Types & Converters
The everyday types and the tools to convert between them.
Value types
| Type | Holds | Example |
|---|---|---|
int | whole numbers | int x = 5 |
long | big whole numbers | long x = 15000000000L |
double | decimals | double x = 5.99 |
float | decimals (less precision) | float x = 5.99F |
decimal | high-precision decimals | decimal x = 5.99M |
char | one character | char x = 'A' |
bool | true/false | bool x = true |
Reference types
| Type | Holds | Example |
|---|---|---|
string | text | string s = "Hi" |
object | anything | object o = 5 |
| arrays / collections | groups | int[] a = {1,2} |
Converters
| Task | Tool |
|---|---|
| string -> int | int.Parse(s), Convert.ToInt32(s) |
| any -> string | Convert.ToString(x), x.ToString() |
| int -> double | implicit, or Convert.ToDouble |
| double -> int | (int) x (truncates) |
Numeric suffixes
5F float, 5M decimal, 5L long, 5D double.
TL;DR
- Value types hold data directly; reference types hold references.
int.ParseandConverthandle conversions.- Suffixes mark float/decimal/long literals.