In the code below, I have a class Foo which implements the IFoo interface. I am passing List of Foo to TestFoo1 and TestFoo2 functions. The compiler for TestFoo2 throws an error where as TestFoo1 works fine...
Why is this? does IEnumerable in the backend convert List Foo to IFoo interface ?
void Main()
{
var foo = new Foo { Name = "Test" };
List<Foo> foos = new List<Foo>();
foos.Add(foo);
TestFoo1(foos);//works
TestFoo2(foos);//compiler error
}
public static void TestFoo1(IEnumerable<IFoo> footest)
{
}
public static void TestFoo2(List<IFoo> footest)
{
}
public class Foo : IFoo
{
public string Name { get; set; }
}
public interface IFoo
{
string Name { get; set; }
}