Use params to mark parameter : params « Language Basics « C# / C Sharp






Use params to mark parameter

 

using System;

class ParamsSample {
    static void PrintStrings(params String[] StringArray) {
        for (int i = 0; i < StringArray.Length; i++)
            Console.Write("{0} ", StringArray[i]);

        Console.WriteLine();
    }

    static void Main(String[] args) {
        String names = "K";
        PrintStrings("A");
        PrintStrings(names, "R", "S");
        PrintStrings("R", "E", "C", "S");
    }
}

 








Related examples in the same category

1.Params Array
2.Normal parameter and params parameters
3.Check the array length for params parameters
4.use the params feature to write functions which accept a variable number of arguments