Is there a relatively straightforward way to get the intersection of two DataTables in .NET?
I can think of the obvious ways (iterating over both tables myself in O(
With .NET 3.5:
using System.Data;
public static class DataTableExtensions
{
public static IEnumerable Intersect(this DataTable table, DataTable other)
{
return table.AsEnumerable().Intersect(other.AsEnumerable());
}
public static IEnumerable Intersect(this DataTable table, DataTable other, IEqualityComparer comparer)
{
return table.AsEnumerable().Intersect(other.AsEnumerable(), comparer);
}
}