در مورد ساخت متد که تعداد آرگومان های متفائتی بتواند اختیار کند از کلمه کلیدی params استفاده کنید.
تعریف MSDN از Params
The params keyword lets you specify a method parameter that takes an argument where the number of arguments is variable.
مثال از MSDN
// cs_params.cs
using System;
public class MyClass
{
public static void UseParams(params int[] list)
{
for (int i = 0 ; i < list.Length; i++)
{
Console.WriteLine(list[i]);
}
Console.WriteLine();
}
public static void UseParams2(params object[] list)
{
for (int i = 0 ; i < list.Length; i++)
{
Console.WriteLine(list[i]);
}
Console.WriteLine();
}
static void Main()
{
UseParams(1, 2, 3);
UseParams2(1, 'a', "test");
// An array of objects can also be passed, as long as
// the array type matches the method being called.
int[] myarray = new int[3] {10,11,12};
UseParams(myarray);
}
}
1
2
3
1
a
test
10
11
12
اما در مورد نمونه مثالی که زدید، می توانید به کلاس SqlHelper مراجعه کنید. (در مورد این کلمه در google جستجو کنید)