[Mono-list] About Arrays of X

Tum tum@veridicus.com
Sun, 15 Dec 2002 04:28:31 +1300


> -----Original Message-----
> From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com]
On
> Behalf Of yoros@wanadoo.es
> Sent: Sunday, 15 December 2002 3:34 a.m.
> To: Tum
> Cc: yoros@wanadoo.es; 'mono-list'
> Subject: Re: [Mono-list] About Arrays of X
> 
> On Sun, Dec 15, 2002 at 02:14:57AM +1300, Tum wrote:
> > Hi,
> >
> > It won't work because int[] is an array of value types whereas
> > IComparable[] is an array of reference types.  If you used 'int[]'
> > instead of Integer[] in Java you'd get the same problem.
> >
> > The solution would be to box the ints by putting them inside an
> > IComparable[] array instead of an int[] array.
> 
> I thought that in C#, a int type was the same that a Int32 class and,
> for this reason, I tried to do it.
> 

It is, but Int32 is a value type not a reference type.  The array would
contain the actual values and not a reference to the values.

> I'm trying to change int[] to IComparable[] but I don't like it :D

The best thing to do (if performance is an issue) might be to pass in an
int[] array and an IComparator.

^Tum