Data Type

The C# variables are divided into the categories below -.

  • Value types
  • Reference types
  • Pointer types

Value Type

Value types can be directly assigned to a value. They come from the system class. ValueType.

The kind of value contains data directly. Examples include int, char, and float, which hold numbers, alphabet numbers, and floating points. The system assigns the memory to keep the value when you declare an int type.

You can use the size method to achieve the exact size of a type or a variable on a specific platform. The size(type) expression gives the object's storage size or the byte type.

Reference Type

However, the reference types include a reference to those variables, not the actual data contained in the variable.

They mean a memory location, in other words. The reference types can refer to a memory location using several variables. The other variable immediately reflects this value change if the data in the memory location is modified by one variable. Examples of integrated types of references are entity, reactive, and string.

Object Type

Object Type is the ultimate basic class in the common type system for all data types (CTS). The object is a system alias—class of object. Object type values of any other type, type of value, reference, predefined, or user type are assigned to object types. But it requires a conversion of the type before allocating values.

When a value type is converted to an object, boxing is called, and when an object type is converted to a value type, unpacking is called.

Dynamic Type

In the dynamic data type variable, you can store any value. The type check is conducted during runtime for certain types of variables.

String Type

You can assign any string value to a variable by the String Type. The type string is a system alias—class of string, and the object type is derived. The value can be given in two forms: quote and @quoted using a literal string.

Pointer Type

Pointer variable type saves a different type of memory address. C# pointers are the same as the C or C++ pointers.