1.Value Parameter
when a parameter is passed to a method using a value, the compiler makes a copy of the value of the argument and passes the copy to the method . The called method does not pass the value of an in-memory argument, so when you use a value parameter, you can guarantee that the actual value is safe.
usingSystem;classtest{Static voidSwap (intXinty) {inttemp=x;x=Y;y=temp;}Static voidMain () {intI=1, j=2; Swap (I,J); Console.WriteLine ("I={0},j={1}", i,j);}}
i=1,j=2
2.Reference type Parameters
Unlike a value parameter, a reference parameter does not open a new area of memory. When you pass a parameter to a method with a reference argument, the compiler passes the actual value in memory to the method.
usingSystem;classtest{Static voidSwap (ref intXref inty) {inttemp=x;x=Y;y=temp;}Static voidMain () {intI=1, j=2; Swap (refIrefj); Console.WriteLine ("I={0},j={1}", i,j);}}
I=2,j=1
C # Reference type (Class) and value type (struct)