Function Which can accept n-number of argument.

By Super Man

Here i will show how to use parameter array ( params ) to accept n-number arguments.


    protected void add(params int[] arr)
    {
         int total = 0;
        foreach (int i in arr)
        {
            total += i;
        }
         
    }

above function can be called with n-number of argument.
   add(1, 2, 3, 4, 5, 6, 7, 9, 10);
   add(1, 2, 3, 4, 5, 6, 7, 9);
   add(1 );

Function Which can accept n-number of argument.  (737 Views)