In C# all variables have a type, which determines what kind of data they store. There are two types of type, value and reference.

Value Types

Value types store a value.

Here is the list of value types in C#:

C# type keyword.NET type
boolSystem.Boolean
byteSystem.Byte
sbyteSystem.SByte
charSystem.Char
decimalSystem.Decimal
doubleSystem.Double
floatSystem.Single
intSystem.Int32
uintSystem.UInt32
nintSystem.IntPtr
nuintSystem.UIntPtr
longSystem.Int64
ulongSystem.UInt64
shortSystem.Int16
ushortSystem.UInt16

Reference Types

Reference types store a reference to something (kind of like a pointer in C) Notably, all objects (instances of a class) are reference types!

Here is the list of reference types in C#:

C# type keyword.NET type
objectSystem.Object
stringSystem.String
delegateSystem.Delegate
dynamicSystem.Object

The “var” keyword

The var keyword allows C# to perform something called type inference, where the runtime decides what type something is based on what value is assigned to it.

For example:

var a = 1;        // a becomes an integer
var b = 1.123;    // b becomes a float
var c = "Hello!"; // c becomes a string

Note that this can only be used when the compiler knows what the type is upon compilation!

The following is not legal:

int add(var a, var b) {
	return a+b;
}