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
 
Back
Top