"Differences between reference types and value types"
//reference type (due to the use of ' class ')classSomeref { PublicInt32 x;}//value type (due to the use of ' struct ')structSomeval { PublicInt32 x;}Static voidValuetypedemo () {someref R1=NewSomeref ();//allocate on the heapSomeval V1 =NewSomeval ();//Allocate on Stackr1.x =5;//To raise another pointerV1x =5;//Modify on StackConsole.WriteLine (r1.x);//Show "5"Console.WriteLine (v1.x);//Show "5"someref R2= R1;//Copy only references (pointers)Someval v2 = v1;//assigning and copying members in the stackr1.x =8;//r1.x and r2.x will change .v1.x =9;//v1.x will change, but v2.x is unchangedConsole.WriteLine (r1.x);//Show "8"Console.WriteLine (r2.x);//Show "8"Console.WriteLine (v1.x);//Show "9"Console.WriteLine (v2.x);//Show "5"}
Plot
Read the Classics-"CLR via C #" (Jeffrey Richter) Notes _ reference type and value type (ii)