I. Introduction to Data Type
Data Types in C# are used to inform the compiler about the type, size & nature of data that can be stored in a variable.
Whenever we need to declare a variable, we need to inform the compiler about the data size & type of the variable.
There are 3 types of data types available in C# programming, which are:
1. Value Data Type
2. Pointer Data Type
3. Reference Data Type
C# mainly categorized data types in two types: Value types and Reference types. Value types include simple types (such as int, float, bool, and char), enum types, struct types, and Nullable value types. Reference types include class types, interface types, delegate types, and array types. Learn about value types and reference types in detail in the next chapter.
I.1. Value Types (Primitive Types)
C# includes some predefined value types and reference types. The following table lists predefined data types:
I.2. Reference TypesThere are two kinds of types in C#: reference types and value types. Variables of reference types store references to their data (objects), while variables of value types directly contain their data. With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable. With value types, each variable has its own copy of the data, and it's not possible for operations on one variable to affect the other (except in the case of
in
, ref
, and out
parameter variables; see in, ref, and out parameter modifier).
0 Comments