我试图找出除了Enumerable.Range
在 WHERE 子句中一对一比较对象的元素之外还有什么更好的方法。
这可能是平行的,因为我们在这里一对一比较。
例如:House.Windows[0].color != House1.Windows[0].color
然后 movenext to
House.Windows[1].color != House1.Windows[1].color
等等...
两个列表中的类型将相同。
public class House
{
string HouseNmbr;
List<Window> windows;
}
public class Window
{
string WSize;
string WColor;
bool IsEnergyEff;
}
public static class MyMain
{
void Main()
{
House h1 = new House
{
HouseNmbr = "1",
windows = new List<Window> {
new Window {Wsize="1", WColor = "blue",IsEnergyEff = true},
new Window {Wsize="1", WColor = "black"},
new Window {Wsize="1", WColor = "red"}
}
};
House h2 = new House
{
HouseNmbr = "1",
windows = new List<Window> {
new Window {Wsize="2", WColor = "blue",IsEnergyEff = false},
new Window {Wsize="2", WColor = "black"}
}
};
//Find the diffs...
IEnumerable<House> updatesFromHouses = from id in h2 //Since h2 will have updates
join pd in h1
on id.HouseNmbr equals pd.HouseNmbr
select new House
{
windows = pd.windows.Where(
wn => Enumerable.Range(0, wn.windows.Count).All(ctr => wn.IsEnergyEff != id.windows[ctr].IsEnergyEff)
).ToList()
};
}
}