J
JxkeZ
Guest
I currently have two List<DataRow> - one that contains DataRows I need to keep, and the other contains a much larger set of DataRows. The List<DataRow> dataToKeep contains the rows I need to keep, and the List<DataRow> dataToRemove contains a large set of values. I need to update the dataToRemove List<DataRow> to contain all values that are not in dataToKeep. So how can I go about removing the values in dataToRemove that are also in dataToKeep?
Here is the code -
List<DataRow> dataToKeep = new List<DataRow>();
List<DataRow> dataToRemove = new List<DataRow>();
foreach (DataRow r in table.Rows)
{
dataToKeep.Add(r);
}
foreach (DataRow r in allData.Rows)
{
dataToRemove.Add(r);
}
dataToRemove.RemoveAll(item => dataToKeep.Contains(item));
foreach (DataRow r in dataToRemove)
{
foreach (var item in r.ItemArray)
{
Console.WriteLine(" | " + item);
}
Console.WriteLine();
}
I think the issue line is
dataToRemove.RemoveAll(item => dataToKeep.Contains(item));
Also, something I thought about is that maybe it is because I cannot compare the Rows to be equal, but is there an efficient way to compare the values within the DataRows to be equal? I didn't know how to do that, but is there a way to compare the values of DataRows rather than the DataRows themselves efficiently? Like a version of .Equals() but for DataRows instead of ==.
I left it to run overnight (very large set of data) and it never got passed that line. How can I do this more efficiently / so it actually works?
Continue reading...
Here is the code -
List<DataRow> dataToKeep = new List<DataRow>();
List<DataRow> dataToRemove = new List<DataRow>();
foreach (DataRow r in table.Rows)
{
dataToKeep.Add(r);
}
foreach (DataRow r in allData.Rows)
{
dataToRemove.Add(r);
}
dataToRemove.RemoveAll(item => dataToKeep.Contains(item));
foreach (DataRow r in dataToRemove)
{
foreach (var item in r.ItemArray)
{
Console.WriteLine(" | " + item);
}
Console.WriteLine();
}
I think the issue line is
dataToRemove.RemoveAll(item => dataToKeep.Contains(item));
Also, something I thought about is that maybe it is because I cannot compare the Rows to be equal, but is there an efficient way to compare the values within the DataRows to be equal? I didn't know how to do that, but is there a way to compare the values of DataRows rather than the DataRows themselves efficiently? Like a version of .Equals() but for DataRows instead of ==.
I left it to run overnight (very large set of data) and it never got passed that line. How can I do this more efficiently / so it actually works?
Continue reading...