Considerations for using parameter arrays:
1. Use the params keyword only on one-dimensional arrays.
2. You cannot overload a method that is based on the params keyword only. The params keyword does not form part of the method's signature.
Such as:
Compile-time error: Duplicate access
public static int Min (int [] paramlist)
.............
public static int Min (params int [] paramlist)
.............
3. The ref or out params array is not allowed
Compile-time error
public static int Min (ref params int [] paramlist)
.............
public static int Min (out params int [] paramlist)
.............
4. The params array must be the last parameter of the method (i.e. there can be only one params array parameter)
public static int Min (params int [] paramlist,int i)
.............
5. The compiler will check and reject any overloads that may be ambiguous
6. The non-params method always takes precedence over a params method. In other words, if you prefer, you can still create an overloaded version of a method for normal situations.
such as: Public Static intMin (intLefthandside,intrighthandside) better than: Public Static intMin (params int[] paramlist)usingSystem; Public classMyClass { Public Static voidUseparams (params int[] list) { for(inti =0; I < List. Length; i++) {Console.WriteLine (list[i]); } Console.WriteLine (); } Public Static voidUSEPARAMS2 (params Object[] list) { for(inti =0; I < List. Length; i++) {Console.WriteLine (list[i]); } Console.WriteLine (); } Static voidMain () {Useparams (1,2,3); USEPARAMS2 (1, the the; a&# the;, "test"); An array of objects can also is passed, as Long asThe array type matches the method being called. int[] MyArray =New int[3] {Ten, One, A }; Useparams (myarray); }} The output of the program is as follows:1231atestTen One A
Use of the parameter array (params)