Why can't I pass IList<ChildType> to F(IEnumerable<ParentType>)?
<p>I figured I could pass an <code>IList&lt;ChildClass&gt;</code> as an <code>IEnumerable&lt;ParentClass&gt;</code>, since obviously each object in a ChildType list is also an instance of ParentType.  But I'm gettin no love from the compiler.  What am I missing?</p>

<p>EDIT: Added function Foo3 which does what I want.  Thanks!</p>

<pre><code>namespace StackOverflow
{
    public class ParentClass
    {
    }

    public class ChildClass : ParentClass
    {
    }

    public class Test
    {
        // works
        static void Foo(ParentClass bar2)
        {
        }

        // fails
        static void Foo2(IEnumerable&lt;ParentClass&gt; bar)
        {
        }

        // EDIT: here's the right answer, obtained from the 
        // Charlie Calvert blog post 
        static void Foo3&lt;T&gt;(IEnumerable&lt;T&gt; bar) where T : ParentClass
        {
        }

        public static void Main()
        {
            var childClassList = new List&lt;ChildClass&gt;();

            // this works as expected
            foreach (var obj in childClassList)
                Foo(obj);

            // this won't compile
            // Argument '1': cannot convert from 
            // 'System.Collections.Generic.List&lt;ChildClass&gt;' 
            // to 'System.Collections.Generic.IEnumerable&lt;ParentClass&gt;' 
            Foo2(childClassList);

            // EDIT: this works and is what I wanted
            Foo3(childClassList);
        }
    }
}
</code></pre>
