I have two questions:
Question 1 Background : I noticed when looking at the implementation of 'AsEnumerable()' method in LINQ from Microsoft, which was:
public static IEnumerable<TSource> AsEnumerable<TSource>(this IEnumerable<TSource> source)
{
return source;
}
Question 1: I was expecting some kind of casting or something here , but it simply returns the value it was passed. How does this work ?
Question 2/3 Background : I have been trying to understand Covariance , contravariance and Invariant. I think, I have a vague understanding that 'in' and 'out' keywords determine the polymorphic behavior when assigning a subtype to a parent type.
Question 2: I know from reading that IEnumerable is covariant, and List is invariant then why is this not possible :
List<char> content = "testString".AsEnumerable();
Question 3:
If IList implements IEnumerable then why is this not possible :
IEnumerable<char> content1 = "testString";
IList<char> content2 = content1;
Please help me understanding, thank you in advance.