I was wondering , why does IEnumerable<T>
has ONLY the out
and not the in
contravariant flag ?
public interface IEnumerable<out T>
I can understand the out
by this example :
IEnumerable<string> strings = new List<string>(){"a","b","c"};
IEnumerable<object> objects = strings;
object
is bigger than string
, so the compiler afraid that well do something like:
objects = objects.First().Select(x=>5);// ( we cant insert int to string...)
fine and understood.
but what about if i want to use the IEnumerable as insertion?
something like :
IEnumerable<object> objects = ...;
IEnumerable<string> strings = objects
so i can also INSERT into objects ...
but the problem is that there is no IEnumerable<in T>
...
am I missing something here?