public class SomeClass
{
public SomeClass(SomeType[] elements)
{
}
public SomeClass(params SomeType[] elements)
{
}
}
I printed this code and got CS0111 error. I'm surprised, are SomeType[] elements
and params SomeType[] elements
the same arguments?
params
keyword does not change method signature. – Contemplationparams
is not the part of the signature of the function. – Mariandiparams
is just a metadata keyword for the C# compiler and has no bearing on the method signature nor on the compilation of the method itself. Basically,params
is just an instruction for the compiler regarding call sites (i.e. callers) of this method to translate a method call in source code likeSomeFooWithParams(1, 2, 3, 4)
intoSomeFooWithParams(new[] { 1, 2, 3, 4 })
(for simplicity, lets ignore right now any other non-params parameters a method might declare...) – Powers