CSharp - Method Method Parameter


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 byVariable must be definitely assigned
N/A Value Before Going in
ref ReferenceBefore 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   ww w .  ja v a2s  .c o  m*/
    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


Related Topics