About

I am a software developer in Seattle, building a new AI software company.

Ads

August 2009

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Ads


« E-books | Main | C# Changes »

June 06, 2004

Comments

dakotahnorth

Is the following scenario also considered covariance ... and do you know if it will be supported in the whidbey release?

If the delegate is ...

public delegate MyClass MyDelegate(MyClass arg);

Is

MyClass Foo(MyDerived arg);

also covariance and supported?

Shhhhhhh

It's still there in B2

xtian

dakotahnorth - no, that's what he says in the last paragraph.

Think of the actual code - somewhere (probably in the defining class), you'll have some code that calls an instance of the delegate, passing a MyClass argument.

If you've created the delegate instance around a method a that expects a MyDerived parameter, a MyClass argument to that method could be a MyDerived, but it could equally well be a MyDerived2 (which subclasses MyClass). If you're relying on members of MyDerived (which is why you'd specify that type), you aren't going to find them on an instance of MyClass or MyDerived2.

If the code compiled successfully, you'd get an invalid cast exception at runtime. So the compiler says "No, that's an implicit downcast, which isn't safe."

The comments to this entry are closed.