A method can have a sequence of parameters.
The caller of the method must provide the arguments.
You can control how parameters are passed with the ref and out modifiers:
Parameter modifier | Passed by | Variable must be definitely assigned |
---|---|---|
N/A | Value | Before Going in |
ref | Reference | Before Going in |
out | Reference | Before Going out |
In this example, the method Test has a single parameter named p, of type int:
using System; class MainClass/*from w w w . j a v a2 s. com*/ { static void Test (int p) { p = p + 1; // Increment p by 1 Console.WriteLine (p); // Write p to screen } public static void Main(string[] args) { Test (8); // Call Test with an argument of 8 } }