Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why .Concat method's return value type looks a bit weird: System.Linq.Enumerable+(...)?

I have 2 instances:

     foo and bar

Their types are:

 foo.GetType().ToString()

returns: System.Collections.Generic.List`1[MyNameSpace.MyClass]

bar.GetType().ToString()

returns: System.Collections.Generic.List`1[MyNameSpace.MyClass]

When I concatanate them:

var foobar = foo.Concat(bar);

The GetType() returns System.Linq.Enumerable+d__71`1[MyNameSpace.MyClass]

Question: What does this mean? Should not it be IEnumerable ?

like image 537
pencilCake Avatar asked Feb 19 '23 06:02

pencilCake


1 Answers

Don't confuse the declared return type and the actual type of the returned value. Concat is declared to return IEnumerable<T>, but it actually returns an instance of a concrete type that implements IEnumerable<T>. GetType returns the concrete type, not the declared return type.

As for the weird name, Concat is implemented with an iterator block, and iterator blocks are transformed by the compiler into types with names such as Enumerable+d__71 that implement IEnumerable<T>.

like image 90
Thomas Levesque Avatar answered Feb 21 '23 21:02

Thomas Levesque