Stoitcho Goutsev (100) [C# MVP] <10*@100.com> wrote:
Could you give us some real life example of where you could use that.
Here's a *really* simple example: ICloneable.
ICloneable defines Clone's return type to be object, when actually you
almost *always* end up casting the result to the type you know it will
be - the same type as the instance you're calling it on.
So, if I want to clone an ArrayList, I need:
ArrayList copy = (ArrayList) original.Clone();
If ArrayList could have declared
ArrayList Clone()
{
....
}
we wouldn't need to do this.
Now in fact, this *is* done all over the framework already, using
explicit interface implementation - look at the various database
classes (SqlConnection, SqlCommand etc). It's a nasty hack around the
lack of covariant return types, and it would have been much nicer if a
single method could have been declared, instead of one for the generic
version and one for the concrete subtype.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too