Q:

Colletion with derived class parameter

I have this classes and method
public class Base{ // members;}
public class Derived : Base{// members} 
myMethod(IEnumerable<Base> in1);

Try to call myMethod like that :
myMethod(IEnumerable<Derived > in2);

and get compilation error?
how should I solve that

A:

What you're expecting is called covariance. It means that the actual generic type is more specific than the required one. You can see that covariance does not work for all generic classes: A List<Derived> should not be assignable to a List<Base>, because then what would happen if you add Base intances to the list, which is actually a list of Derived instances? So IEnumerable is covariant and IList is invariant.
This concept has been applied to the collection classes in .NET 4.0. When you are using a version of .NET < 4, those classes are invariant.

