Lesson 49 +10 XP

Cheatsheet: Common Types & Converters

Cheatsheet: Common Types & Converters

The everyday types and the tools to convert between them.

Value types

TypeHoldsExample
intwhole numbersint x = 5
longbig whole numberslong x = 15000000000L
doubledecimalsdouble x = 5.99
floatdecimals (less precision)float x = 5.99F
decimalhigh-precision decimalsdecimal x = 5.99M
charone characterchar x = 'A'
booltrue/falsebool x = true

Reference types

TypeHoldsExample
stringtextstring s = "Hi"
objectanythingobject o = 5
arrays / collectionsgroupsint[] a = {1,2}

Converters

TaskTool
string -> intint.Parse(s), Convert.ToInt32(s)
any -> stringConvert.ToString(x), x.ToString()
int -> doubleimplicit, 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.Parse and Convert handle conversions.
  • Suffixes mark float/decimal/long literals.