Re: Code calls method with wrong signature (object vs object[])
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: 16 Aug 2006 05:24:41 -0700
LordHog@xxxxxxxxxxx wrote:
The strange item which I don't understand is that instead of call the
method that accepts an array of objects the code is calling the method
where the signature only accepts a single object. Can someone explain
why this is? My guess is since object is the base class of most items
it is also the base class for arrays. Any explanation will be
appreciated. For the time being I will just end up change the method
names to force call to the correct method istead of relying on the
compiler looking at the signature.
Changing the method names won't help you, as a byte[] isn't an
object[]. The problem is that while *arrays of reference types* are
covariant, arrays of value types aren't. For instance:
string[] stringArray = new string[10];
object[] objectArray = stringArray; // Fine
but
byte[] byteArray = new byte[10];
int[] intArray = byteArray; // No conversion available
object[] objectArray = byteArray; // No conversion available
The other posts give suggested solutions.
Jon
.
- References:
- Prev by Date: Problem with mshtml .. won't work on some comps
- Next by Date: Re: hi
- Previous by thread: Re: Code calls method with wrong signature (object vs object[])
- Next by thread: Drawing in a picturebox
- Index(es):
Relevant Pages
|