【发布时间】:2013-07-17 10:40:39
【问题描述】:
我试图找出除了 WHERE 子句中的Enumerable.Range 之外还有什么更好的方法来一对一地比较对象的元素。
这可能是平行的,因为我们在这里是一对一比较。
例如:House.Windows[0].color != House1.Windows[0].color 然后移到
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()
};
}
}
【问题讨论】:
-
粘贴一些代码,你需要什么类型的输出?
-
我不明白你想要完成什么。
-
抱歉没有粘贴代码以便清晰理解。
-
@JackSmotheir 你的 Enumerable.Range 在哪里?列表中的位置在这里很重要吗?例如。如果第二个房子先有黑窗呢?
-
你想要的结果到底是什么?
标签: c# .net performance linq linq-to-entities