Using system;using system.collections.generic;using system.linq;using system.text;using system.threading.tasks;namespace consoleapplication1{ class program{ static int val; //function //1. keyword static: static function, void: no return value, Return: The program returns the calling code immediately; //instance 1: function Parameters static double product (DOUBLE PARAM1, DOUBLE PARAM2) {            RETURN PARAM1 * PARAM2;} //Instance 2: parameter array static int add (params int[] p) { int sum = 0; foreach (int i in  P) sum += i; return sum;} //instance 3: value transfer function, the result does not change static void showdoulbe (Int val) { val *= 2; console.writeline ("val doubled ={0}", val);} //instance 4: no parameter function, result change static void showdoulbe () { val *= 2; conSole. WriteLine ("val doubled ={0}", val);} //Instance 5: Reference transfer function, result change static void showdoulbe (Ref int val) { val *= 2; console.writeline ("val doubled ={0}", val);} //instance 6: output function static void outfun (OUT STRING STR) { str = "Test"; str += "Fun"; Console.WriteLine ("Outfun result: {0}", str);} static&nbSp;void main (String[] args) { Call function Parameter console.writeline ("Call func parameter; "); double a = product (1.2, 2.1); console.writeline (a); //Call parameter array console.writeline ("call parameter array;"); int sum = add (1, 3 , 5, 7); console.writeline ( sum); //call no parameter function, result change &Nbsp; console.writeline ("call non-parameter func;"); val = 5; console.writeline ("befor the call;"); console.writeline ("myNumber={0}", val); console.writeline ("After the call; "); showdoulbe (); console.writeline ("mynumber={0}", val); //Call value transfer function, result does not change console.writeline ("call value-passed func;"); int mynumber = 5; console.writeline ("befor the call;"); console.writeline ("myNumber={0}", mynumber); console.writeline (" after the call; "); showdoulbe (MyNumber); console.writeline ("myNumber={0}", myNumber); //Invoke reference transfer function, result change console.writeline ("call reference-passed func;"); int myNumber2 = 5; &nBsp; console.writeline ("befor the call;"); console.writeline ("myNumber={0}",  MYNUMBER2); console.writeline (" after the call; "); showdoulbe (Ref myNumber2); console.writeline ("myNumber={0}", MYNUMBER2); //Call output function console.writeline ("call out parameter function; "); string test2; outfun (OUT TEST2); &nbSp; console.readline ();}}}
This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1650866
10.c#--function parameter, parameter array, value transfer function, reference transfer function, output function, parameterless function