Generic co- and contravariance Interfaces with WP7?

27. October 2010

Inspired by a question in the german Windows Phone 7 msdn forum about the possibility of using generic covariance interfaces in WP7 development, I`m writing this blogpost.

Generic covariance and also contravariance for interfaces and delegates were introduced as new features in C#4.0. Also two new modifiers for type parameters came along with it –> in and out, which indicate wether the interface or delegate is co- or contravariant.

Here`s a little code-snippet:


While this works fine on the desktop, I figured out that one isn`t able to use this feature for windows phone 7 development!

It`s because of the .NET Compact Framework CLR, which runs on a WP7 device. While you write Silverlight or XNA applications, it`s limited to the Compact Frameworks CLR, which doesn`t support the newest C#4.0 features such as generic co- and contravariance for interfaces.

But I come to the conclusion that the lack of this feature is no big deal! 🙂 Just wanted to share this experience…


One Response to “Generic co- and contravariance Interfaces with WP7?”

  1. […] using the "in" and "out" keywords. The original interface definition used this until I realized they are no-go on the phone. Basically, the IDE and compiler will allow you to define them, but at runtime they fail with a […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: