我正在使用DataSets,特别是一个DataRows数组:
我的问题是,我如何才能在不使用LINQ的情况下执行DataRow[]的并集/交集?
发布于 2009-12-09 04:49:25
就我个人而言,我是通过在表之间使用Relations来做到这一点的。
发布于 2009-12-09 04:51:56
使用Relations
发布于 2009-12-09 04:55:32
只需为其编写代码即可:
//Assumes setA and setB are unique internally
public DataRow[] GetUnionRows(DataRow[] setA, DataRow[] setB){
List<DataRow> resultList = new List<DataRow>(setA);
foreach (DataRow row in setB){
if (!Contains(setA, row)){
resultList.add(row);
}
}
return resultList.toArray();
}
private bool YourEquals(DataRow a, DataRow b){
//Whatever
}
private bool Contains(DataRow[] setA, DataRow b){
foreach(DataRow a in setA){
if (YourEquals(a,b)){
return true;
}
}
return false;
}https://stackoverflow.com/questions/1869710
复制相似问题