Use params to mark a parameter : Variable Length Parameters « Language Basics « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;



class Program {
    static int SumVals(params int[] vals) {
        int sum = 0;
        foreach (int val in vals) {
            sum += val;
        }
        return sum;
    }

    static void Main(string[] args) {
        int sum = SumVals(1, 5, 2, 9, 8);
        Console.WriteLine("Summed Values = {0}", sum);

    }
}








1.15.Variable Length Parameters
1.15.1.Variable-Length Parameter Lists
1.15.2.Use params to mark a parameter