Regarding the type of static return of the collection method, C # supports overloading LINQ extension methods ( Select , Where , etc.) and automatically selects the most specific scope. Therefore, Seq.Select can return Seq , Enumerable.Select can return Enumerable , etc. This is very similar to how the most specific implicit implementation is chosen in Scala.
As for the dynamic type, LINQ operations are implemented as extension methods, so dynamic dispatch is not performed. So (Seq as Enumerable).Select will return Enumerable , not Seq . In Scala, collection method calls are dynamically sent, so the dynamic type will remain unchanged for map , filter , etc. Both approaches have advantages / disadvantages. The only clean solution to this kind of problem is the ellipsis of IMHO, and neither language nor runtime support them effectively.
Regarding runtime behavior, LINQ always returns a lazily evaluated collection view. There is no method on the view that magically returns a collection of the original type, you need to manually specify what you want, for example, an array using the toArray method. IMHO, this is a cleaner and simpler approach than the one used by Scala, and lazy addition operations are better than strict ones, but this involves an additional method call to get a strict collection for single collection operations.
Jesper nordenberg
source share