Variable number of method parameters

  • Thread starter Thread starter Aleksei Guzev
  • Start date Start date
A

Aleksei Guzev

Hi,

I have the following code:

public struct IntegerList
{
ArrayList _rep;

public IntegerList( int [] vals )
{
_rep = new ArrayList( vals );
}

public IntegerList( params int[] v )
{
_rep = new ArrayList( v );
}
}

Why the compiler treats the constructors as ones having the same parameter
types? (CS0111)

Aleksei Guzev
 
Quite logical actually.

Let us assume that you are initializing the struct with an array of
integers....

which code segment do you expect that the run time calls? Passing an array
of integers would satisfy the signatures of both the constructors.


That is why we get an error....

-D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top