Brahma Prakash Shukla
Create a function in C# which can accept varying number of arguments?

Create a function in C# which can accept varying number of arguments?

By Brahma Prakash Shukla in .NET on Oct 28 2022
  • Pankaj Patel
    Nov, 2022 17

    Hi Brahma Prakash Shukla,

    params“ can be used to create a function in C# which can accept varying number of arguments as like following:

    1. void PrintReport(string header, params int[] numbers)
    2. {
    3. Console.WriteLine(header);
    4. foreach (int number in numbers)
    5. Console.WriteLine(number);
    6. }

    For more details:

    Function with variable number of arguments
    https://stackoverflow.com/questions/9784630/function-with-variable-number-of-arguments

    Hope, this will help you!

    • 3
  • Naeem Khan
    Nov, 2022 27

    // function containing params parameterspublic static int Add(params int[] ListNumbers){int total = 0;// foreach loopforeach(int i in ListNumbers) {total = i;}return total;}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS