本文介绍了帮助选择LinQ -C#配对两个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有这样的结构: < PrincipalObject > < SecondObject > < ThirdObject > < fourthObject > < 标识符 > B < / identifier > < 金额 > 5.00 < / amount > < 货币 > EUR < / Currency > < / fourthObject > < fourthObject > < 标识符 > 712 < / identifier > < a mount > 49.51 < / amount > < 货币 > EUR < / Currency > < / fourthObject > < / ThirdObject > < / SecondObject > < SecondObject > < ThirdObject > < fourthObject > < 标识符 > B < / identifier > < 金额 > 7.00 < / amount > < 货币 > EUR < / Currenc y > < / fourthObject > < fourthObject > < 标识符 > 712 < / identifier > < 金额 > 51.51 < /金额 > < 货币 > EUR < /货币 > < / fourthObject > < / ThirdObject > < / SecondObject > < SecondObject > < ThirdObject > < fourthObject > < 标识符 > B < / identifier > < 金额 > 7.00 < /金额 > < 货币 > EUR < /货币 > < / fourthObject > < fourthObject > < 标识符 > 712 < / identifier > < 金额 > 51.51 < / amount > < 货币 > EUR < / Currency > < / fourthObject > < / T hirdObject > < / SecondObject > < SecondObject > < ThirdObject > < fourthObject > < 标识符 > B < / identifier > < 金额 > 8.00 < / amount > < 货币 > EUR < / Currency > < / fourthObject > < fourthObject > < 标识符 > 712 < / identifier > < 金额 > 52.51 < /金额 > < 货币 > EUR < /货币 > < / fourthObject > < / ThirdObject > < / SecondObject > < / PrincipalObject > 我想获得一个对象列表,它们的标识符为B,金额为51.51,标识符为712,金额为51.51。 我尝试(来自 p PrincipalObject.SecondObject 来自 s p.ThirdObject.fourthObject 其中(s.identifier == B&& s.amount == 7. 00 )&& (s.identifier == 712&& s.amount == 51. 51 ) 选择 s)。ToList(); 但这失败了 $ b $b¿我如何比较两个物体? 什么时候是B - >金额= 7 AND 什么时候是712 - >金额= 51.52 非常感谢解决方案 var result = PrincipalObject.SecondObject.Select(p => p.ThirdObject.fourthObject) .Where(s => s.Any(x => x.identifier == B&& x.amount == 7 。 00 )&& s.Any(x => x.identifier == 712&& x.amount == 51 。 51 ))ToList(); I have this structure:<PrincipalObject><SecondObject><ThirdObject><fourthObject> <identifier>B</identifier> <amount>5.00</amount> <Currency>EUR</Currency> </fourthObject><fourthObject> <identifier>712</identifier> <amount>49.51</amount> <Currency>EUR</Currency> </fourthObject> </ThirdObject> </SecondObject><SecondObject><ThirdObject><fourthObject> <identifier>B</identifier> <amount>7.00</amount> <Currency>EUR</Currency> </fourthObject><fourthObject> <identifier>712</identifier> <amount>51.51</amount> <Currency>EUR</Currency> </fourthObject> </ThirdObject> </SecondObject><SecondObject><ThirdObject><fourthObject> <identifier>B</identifier> <amount>7.00</amount> <Currency>EUR</Currency> </fourthObject><fourthObject> <identifier>712</identifier> <amount>51.51</amount> <Currency>EUR</Currency> </fourthObject> </ThirdObject> </SecondObject><SecondObject><ThirdObject><fourthObject> <identifier>B</identifier> <amount>8.00</amount> <Currency>EUR</Currency> </fourthObject><fourthObject> <identifier>712</identifier> <amount>52.51</amount> <Currency>EUR</Currency> </fourthObject> </ThirdObject> </SecondObject> </PrincipalObject>I want get a list of objects that they have the identifier "B" and amount 51.51, and identifier "712" and amount 51.51.I try (from p in PrincipalObject.SecondObject from s in p.ThirdObject.fourthObject where (s.identifier =="B" && s.amount ==7.00) && (s.identifier =="712" && s.amount ==51.51) Select s).ToList();But this fails¿How I can compare two objects?When is B -> amount = 7 ANDWhen is 712 -> amount = 51.52Thank you very much 解决方案 var result = PrincipalObject.SecondObject.Select(p=>p.ThirdObject.fourthObject) .Where(s=>s.Any(x=>x.identifier =="B" && x.amount ==7.00) && s.Any(x=>x.identifier =="712" && x.amount ==51.51)).ToList(); 这篇关于帮助选择LinQ -C#配对两个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-16 23:33