I've seen the params
parameter more times than I can say and always removed it without thinking about it's meaning. Now I've learned its purpose. What I just learned is that the params
parameter must be the last in the parameter list. But this is what I learned about the parameters that have a default value specified. Example:
MyMethod(string Name, int blah=0).
So the question is if I need to specify a default value as above while needing to use params
, can this be done? If so, which must be declared last? Example:
MyMethod(int blah=0, params string[] variableData).
Thanks for your help again. James
Your example is correct:
public void TestMethod(string name = "asdasd", params int[] items)
{
}
params
has to be last, no matter what parameter are used before that.