Using system; using system. collections. generic; using system. LINQ; using system. text; namespace argument {// <summary> // C # by default, real parameters are passed as values. // to pass Parameters as references, C # provide the ref parameter modifier // The parameter can be passed to the function as a value or reference, without considering whether it is a value type or a reference type ///out modifier, similar to ref, but 1. You do not need to assign an initial value when calling a function. 2. You must assign a value before the function is released. // Params modifier is generally used to modify the last parameter, so that it can accept any number of specific types of parameters // Variable Parameter Function in C language, void fun (parm_list ,...); void fun (...); the type can be different. // </Summary> class program {public void Foo (ref int X) {x = x + 1; system. console. writeline ("in Ref foo" + x);} public void Foo (int x) {x = x + 1; system. console. writeline ("in foo" + x);} public void Foo (stringbuilder SB) {sb. append ("ASDF"); system. console. writeline ("in foo" + Sb);} public void split (string name, out string firstname, out string lastname) {int I = Name. lastindexof (''); firstname = Name. substring (0, I); lastname = Name. substring (I + 1);} public int sum (Params int [] ints) {int sum = 0; For (INT I = 0; I <ints. length; I ++) sum + = ints [I]; return sum;} static void main (string [] ARGs) {program P = new program (); int x = 9; p. foo (x); system. console. writeline ("Out foo" + x); p. foo (ref X); system. console. writeline ("out ref foo" + x); stringbuilder STR = new stringbuilder ("Zhang"); p. foo (STR); system. console. writeline ("Out foo" + Str); string a, B; p. split ("Stevie Ray Stewart", out a, out B); system. console. writeline (a); system. console. writeline (B); // Params system. console. writeline (P. sum (1, 2, 3, 4, 5); system. console. writeline (P. sum (New int [] {1, 2, 3, 4, 5 }));}}}
In function overloading, the return value type and Params modifier are not part of the method signature.
The ref and out modifiers can be used as method signatures.