In C#, Objects are Reference type, Class objects contain a pointer (memory addresse) to be addressed. In that case, when an objest is assigned to another, both objects are pointed to same memory addresse.
Structs are value type; struct objects contain the struct itself as its variable. In that case, when an struct object is asssigned to another, assigner object is copied into the new object.
Following code example illustrates it. In code, assigned class object variable (field) displays assigner objects value: instead to show the assigned value. Struct objects display their assigned value as value type. As seen in example, field of object 2 is assigned to 77. However, as class variables are pointer, and object 2 had been assigned to object 1 at declaration: displayed result indicates value of object 1. Because object 1 and object 2, those variables are a memory addresse.
namespace NS_x
{
internal class CL_xClass
{
public int v_1;
}
internal struct ST_xStruct
{
public int v_2;
}
class Program
{
static void Main(string [] args)
{
//2 class object is created to test///
CL_xClass o_1 = new CL_xClass();
CL_xClass o_2 = o_1;
o_1.v_1 = 25;
o_2.v_1 = 77;
Console.WriteLine(o_1.v_1);
Console.WriteLine(o_2.v_1);
//2 struct object is created to test///
ST_xStruct o_3 = new ST_xStruct();
ST_xStruct o_4 = o_3;
o_3.v_2 = 55;
o_4.v_2 = 99;
Console.WriteLine(o_3.v_2);
Console.WriteLine(o_4.v_2);
}
}
}