This is a walk which is effecient. If you use the foreach, as the tables get larger you increase the time by the square (O(x square)). This solution is linear (O(x)):
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
int c1 = 0;
int c2 = 0;
while (c1 < dt1.Rows.Count && c2 < dt2.Rows.Count)
{
if ((int)dt1.Rows[c1][0] == (int) dt1.Rows[c2][0])
{
c1++;
c2++;
}
else if ((int)dt1.Rows[c1][0] > (int)dt1.Rows[c2][0])
{
c2++;
}
else
{
c1++;
}
}
if (c1 < dt1.Rows.Count)
{
}
if (c2 < dt2.Rows.Count)
{
}
If you want to have the results in a table then:
dt3.Rows.Add(dt1.Rows[c1]);
Where dt3 is another table you have defined.