C# has two groups of type, the first group is called the value group and the second group is called the reference group.
The members of these two groups are respectively called value types and reference types.
1) Simple types (char, int etc)
2) Struts
3) Enums
Value types, as above, contain their data.
Reference types point to their object using reference variables.
Value types are more influenced by state related concerns.
Reference types are more influenced behavioural concerns.
Value types are allocated in the memory stack
(if one instance of a value is assigned to another instance the memory stack has two sepeate copies of the value).
Reference types are allocated to the heap
(if one or more instances of a reference type are assigned to an object they all point to the same single object on the memory heap).
More on the memory stack here
Default Types in C#
Name
|
Description
|
| sbyte |
8-bit signed integer |
| short |
16-bit signed integer |
| int |
32-bit signed integer |
| long |
64-bit signed integer |
| byte |
8-bit unsigned integer |
| object * |
Base of all .NET types |
| string * |
Unicode 16-bit string |
| ushort |
16-bit unsigned integer |
|
ulong |
32-bit unsigned integer |
|
float |
single precision floating point |
|
double |
double-precision floating point |
|
bool |
boolean value |
|
char |
unicode character |
|
decimal |
Decimal value pricise to 28 digits |
*=Reference types, all others are Value types.
When compiled all .NET types are self describing, the compiled assembly contains metadata detailing all the types it uses.
One of the key fundamental steps in learning to program with a language is understanding how it treats pre-defined data types.
We apply logic to manipulate these data types using operators that the language provides.
More on language Operators here