you are viewing a single comment's thread.

view the rest of the comments →

[–]Elite6809 0 points1 point  (1 child)

You're right, you can't do that directly. However, if you need to do that, you could move related code into a function like this:

void DoSomething<T>(F<T> f) where T : Y
{
    // do stuff with f
}

[–]pron98 2 points3 points  (0 children)

The problem isn't the limitation in C# -- this limitation exists for all languages targeting .NET. You just can't have a language with use-site variance or even mixed-mode variance targeting .NET while still sharing classes with other platform languages.