top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Does C# support variable argument on method?

+3 votes
194 views
Does C# support variable argument on method?
posted Dec 9, 2013 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Yes. The classic example would be the params object[] args:

//Allows to pass in any number and types of parameters
public static void Program(params object[] args)

or

void Program(string param1, int param2, params double[] otherParams)

Restrictions:
1. They must all be the same type (or of a child type) as is true for arrays as well
2. Only one params keyword is permitted per method
3. It has to be the last parameter.

answer Feb 1, 2014 by Jai Prakash
...