If I have a method as such:
public void Foo<T1, T2>(T1 list) where T1 : IList<T2> where T2 : class {
Now if I have:
IList<string> stringList = new List<string>(); List<object> objectList = new List<object>(); IList<IEnumerable> enumerableList = new List<IEnumerable>();
Then the compiler cannot allow the choice of generators, and this fails:
Foo(stringList); Foo(objectList); Foo(enumerableList);
And you should explicitly specify the general to use as such:
Foo<IList<string>, string>(stringList); Foo<IList<object>, object>(objectList); Foo<List<object>, object>(objectList); Foo<IList<IEnumerable>, IEnumerable>(enumerableList);
generics c #
Cornelius
source share