Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I have two method signatures with the only difference being the "params" keyword for the array parameter?

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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The difference between the two is that one requires a single concrete array, while the other also allows it to be called with individual items such as

SomeClass("Alpha", "Omega", "Gamma")

Choose the params one if you need to call it as above and delete the other. The error speaks to the fact that both are, to the compiler, the same signature SomeType[] hence the error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading