Why. The concat method return type looks a little strange: System.Linq.Enumerable + (...)?

I have 2 instances:

foo and bar 

Their types:

  foo.GetType().ToString() 

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

 bar.GetType().ToString() 

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

When I contact them:

 var foobar = foo.Concat(bar); 

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

Question : What does this mean? Shouldn't it be IEnumerable?

+4
source share
2 answers

Do not confuse the declared return type with the actual return type. Concat declared as a return IEnumerable<T> , but it actually returns an instance of a specific type that implements IEnumerable<T> . GetType returns a specific type, not a declared return type.

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

+8
source

In addition to Thomas's answer, note that the "1" part of the name indicates the number of common arguments. The type for each common argument follows in brackets "[...]".

0
source

Source: https://habr.com/ru/post/1432745/


All Articles