[Mono-list] About Arrays of X
Tum
tum@veridicus.com
Sun, 15 Dec 2002 02:14:57 +1300
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.
^Tum
> -----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 1:38 a.m.
> To: mono-list
> Subject: [Mono-list] About Arrays of X
>
>
> Hi,
>
> I was making a little program that implements a few generic algorithms
> for arrays. I decided that the best option was to define the type of
the
> arguments of the methods to "IComparable []" (array of IComparable)
but
> when I call that method with one "int[]" the compiler tells me the
> following message:
>
> error CS0030: Cannot convert type 'int[]' to 'System.IComparable[]'
>
> I tried to do the same thing in Java (using Integer[] and
Comparable[])
> and it worked.
>
> I think this feature must be in all object oriented languages. In the
> fact, Java, C++, Eiffel, etc... has the feature.
>
> Can anyone tell me how can I make the construction I want ? (int[]
> inside one IComparable[] to get one generic class).
>
> Regards,
>
> Pedro
>
> --
> Pedro Martinez Juliá
> \ yoros@terra.es
> )| yoros@wanadoo.es
> / http://yoros.cjb.net
> Socio HispaLinux #311
> Usuario Linux #275438 - http://counter.li.org
> GnuPG public information: pub 1024D/74F1D3AC
> Key fingerprint = 8431 7B47 D2B4 5A46 5F8E 534F 588B E285 74F1 D3AC