Data Types are used everywhere in a programming language. It means, that you cannot use variable without data types. Data types are used to inform the compiler about what type value variable can store? This is a set of values and allowable operations on those values. Such as if you want to work with int value then you will have to assign int type variable to work with.
C-Sharp provides two types of data types
- Value Types
- Reference Types
These data types contain the directly value. These types are created on the stack and derived from the class
System.ValueType. Primitive types (Except strings), Enumeration, Structure are Value types.
- Bool: Bool is one of the simple data types. It can contain only 2 values – “false” or “true”. The default value of Bool is “false”.
- Int: Int is short for integer, a data type for storing number without decimals. When working with numbers, int is the most commonly used data type. Integers have several data types within C# depending on the size of the number they are supposed to store.
- Char: Char is used for storing a single character.
- Float: Float is one of the data types used to store the decimal value. In C# we have three floating point types: float, double, and decimal.
The Reference types do not contain the actual data stored in a variable, but they contain a reference to the variables. Reference types are created on the Heap. The lifetime of the reference type is managed by the .NET framework. The default value for reference types is null reference. Assignment to a variable of a reference type creates a copy of the reference rather than a copy of the referenced value. Classes, strings, interfaces, arrays, and delegates are reference types.