對於IEnumerable
,LinqKit有一個擴展方法ForEach
,它與System.Collections.Generic.IEnumerable
相沖突。C#歧義擴展方法
Error 4 The call is ambiguous between the following methods or properties:
'LinqKit.Extensions.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)'
and
'System.Linq.EnumerableExtensionMethods.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)'
我怎樣才能擺脫這種錯誤的?
在附註中 - Eric Lippert有一些關於爲什麼'ForEach'擴展方法可能不是最好的想法的一些要點...值得一讀:http://blogs.msdn.com/b/ericlippert/archive /2009/05/18/foreach-vs-foreach.aspx –
說到這些,'System.Linq.EnumerableExtensionMethods'來自哪個庫? – StriplingWarrior
@ReedCopsey Lippert的推理是虛假的,反映瞭如何將函數式編程加入到C#中,很差(例如,'select'而不是'map','aggregate'而不是'foldl',根本沒有'foldr'...)。相比之下,Scala有一個'foreach'方法,即使它有一個迭代集合的'for'語句......事實上,'for'循環擴展爲調用'foreach'(等等)。 Scala支持一種強制性的編碼風格,但以各種方式鼓勵程序員在他們變得更有經驗時逐漸轉向功能風格。 –