4

A simple example using the code snippet below:

using System.Data;
using CustomerNameSpace;
...
...
CDataSet.CustomerDataTable dtCustomer = GetCustomer();

var customersWithName = dtCustomer.AsEnumerable()
    .Where(x => x.Name != null)
    .CopyToDataTable();

For some reason, my coworker has created an extension method CopyToDataTable() within the CustomerNameSpace.

The program in this case is using both namespaces System.Data and CustomerNameSpace.

Both now contains the extension method CopyToDataTable().

In the sample snippet below, is there a way to specify which extension methods from these two namespaces to use?

IvanJazz
  • 763
  • 1
  • 7
  • 19

1 Answers1

5

If you absolutely need both namespaces in your code, the only way to differentiate is to call the method as a 'normal' static method instead of an extension method:

var customers = dtCustomer.AsEnumerable()
    .Where(x => x.Name != null);
CustomerNameSpace.MyExtensionsClass.CopyToDataTable(customers);
jeroenh
  • 26,362
  • 10
  • 73
  • 104