Data Types in the C# are divided into two categories:
•
value types (significant types) in English
"value types"
•
reference types in English and
"reference types"
It's important to understand the differences.
Value Types (value types) in the C#
Value Types contain values and are stored
in the stack ....
C#
Example
static void Main(string[] args)
{
int a = 1;
int b = 2;
b = a;
a = 3;
Console.WriteLine(a); // 3
Console.WriteLine(b); // 1
}
C#
Example
class Test
{
public int x;
}
class Program
{
static void Main(string[] args)
{
Test a = new Test();
Test b = new Test();
a.x = 1;
b.x = 2;
b = a; // link assignment
b.x = 3; // b.x = 3 and automatically a.x = 3
//because b and a point to one place in memory
Console.WriteLine(a.x); // 3
Console.WriteLine(b.x); // 3
}
}