Create a function in C# which can accept varying number of arguments?
Hi Brahma Prakash Shukla,
โparamsโ can be used to create a function in C# which can accept varying number of arguments as like following:
void PrintReport(string header, params int[] numbers){ Console.WriteLine(header); foreach (int number in numbers) Console.WriteLine(number);}
void PrintReport(string header, params int[] numbers)
{
Console.WriteLine(header);
foreach (int number in numbers)
Console.WriteLine(number);
}
For more details:
Function with variable number of argumentshttps://stackoverflow.com/questions/9784630/function-with-variable-number-of-arguments
Hope, this will help you!
// function containing params parameterspublic static int Add(params int[] ListNumbers){int total = 0;// foreach loopforeach(int i in ListNumbers) {total = i;}return total;}