Array As Actual Param: params int[] inVals : params « Language Basics « C# / CSharp Tutorial






using System;

class MainClass {
   public static void ListInts(params int[] inVals)
   {
      if (inVals != null)
         for (int i = 0; i < inVals.Length; i++)   
            inVals[i] = inVals[i] * 10;
   }

   static void Main()
   {
      int[] MyArr = new int[] { 5, 6, 7 };         

      ListInts(MyArr);                          

      foreach (int x in MyArr)
         Console.WriteLine("{0}", x);              
   }
}
50
60
70








1.16.params
1.16.1.Demonstrate params
1.16.2.Use regular parameter with a params parameter.
1.16.3.Mix params array type with other data types
1.16.4.Array As Actual Param: params int[] inVals
1.16.5.Use 'params int[]'
1.16.6.Sending in args using params keyword: object, int and string