Mix params array type with other data types : params « Language Basics « C# / CSharp Tutorial






using System;

class MainClass
{
  public static void ArrayOfInts(string msg, params int[] list) 
  {
    Console.WriteLine(msg);

    for ( int i = 0 ; i < list.Length ; i++ )
      Console.WriteLine(list[i]);
    Console.WriteLine();
  }

  public static void Main() 
  {
    int[] intArray = new int[3] {10,11,12};
    ArrayOfInts("Here is an array of ints", intArray);
    ArrayOfInts("Enjoy these 3 ints", 1, 2, 3);
    ArrayOfInts("Take some more!", 55, 4, 983, 10432, 98, 33);
  }
}
Here is an array of ints
10
11
12

Enjoy these 3 ints
1
2
3

Take some more!
55
4
983
10432
98
33








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