I've ran into problem with extension method resolution. LINQ and MoreLINQ contain zip
method, it was present in .NET since 4.0 version and was always in MoreLINQ library. But you can't use one of the implementation with nice-old extension method syntax. So this code won't compile
using MoreLinq;
using System.Linq;
var students = new [] { "Mark", "Bob", "David" };
var colors = new [] { "Pink", "Red", "Blue" };
students.Zip(colors, (s, c) => s + c );
Error:
The call is ambiguous between the following methods or properties:
'MoreLinq.MoreEnumerable.Zip<string,string,string>
(System.Collections.Generic.IEnumerable<string>,
System.Collections.Generic.IEnumerable<string>, System.Func<string,string,string>)' and
'System.Linq.Enumerable.Zip<string,string,string>
(System.Collections.Generic.IEnumerable<string>,
System.Collections.Generic.IEnumerable<string>, System.Func<string,string,string>)'
I've found good resolution for Concat
method on string
for MoreLINQ made by Jon Skeet at this post, but I'm not aware of good resolution for zip
method.
NOTE: You can always use static method call syntax and it all works fine with
MoreEnumerable.Zip(students, colors, (s, c) => s + c )
but misses the point of extension syntax sugar a little bit. If you have lots of data transformation with LINQ and MoreLINQ calls - you don't want to use static method call in the middle.
Are there any better ways to resolve this ambiguity?
Zip
function) – Schistosomiasiszip
and .NET 4.0 here code.google.com/p/morelinq/issues/detail?id=60 and NoConflict resolution here gist.github.com/2869531 – Lovable