Search code examples
c#.netextension-methodsambiguous-call

How to resolve ambigiously named extension method?


I have a DataTable that I'm trying to enumerate over with the AsEnumerable extension method on System.Linq.Enumerable. The problem is that there is an identically named extension method on System.Data.DataTableExtensions. I need to use both namespaces in my class so removing one of the using statements is not an option.

How do I declare that I want the AsEnumerable method from System.Linq.Enumerable and not the System.Data.DataTableExtensions?


Solution

  • They're just static methods so you could do this:

    DataTable dt;
    System.Linq.Enumerable.AsEnumerable(dt);