Knowledge point:
Value Type and reference type
For the value type, the data stored in the stack is directly used.
For reference types, the stack stores the address of objects in the stack.
Value Transfer and reference Transfer
For value transfer, the data stored in the stack is transmitted.
For reference transfer, the stack address is passed.
Let's take a look at the value transfer (pass the value type and reference type)
Class program {static void main (string [] ARGs) {// assign a value to the reference type, but assign a value to the address of the object in the heap: person P = new person (); // declare a person class that contains the name attribute p. name = "yzk"; d2 (p); console. writeline (P. name); // return value is JK // Value Type assignment, with a specific value assigned, rather than the address int n = 10; D1 (n); console. writeline (n); // the return value is 10 console. readkey ();} // pass the value of the Value Type Static void D1 (INT m) {M = m + 1 ;} // pass the reference type value static void D2 (person P1) {p1.name = "Jk ";}}
Illustration:
Let's look at the reference transfer (pass the value type and reference type)
Class program {static void main (string [] ARGs) {person P = new person (); // declares a person class, which contains the name attribute p. name = "Jk"; d2 (ref P); // reference transfer: the stack address console is passed. writeline (P. name); // return value SK int n = 10; D1 (ref N); // reference transfer: the stack address is passed to the console. writeline (n); // return value 11 console. readkey ();} // pass the reference of the Value Type Static void D1 (ref int A) // ref indicates that the reference is passed {A = a + 1 ;} // pass static void D2 (ref person per) {per = new person (); Per. name = "SK ";}}
Illustration
C # value transfer and reference Transfer