gpt4 book ai didi

c# - 在 LINQ 表达式中加入对象

转载 作者:行者123 更新时间:2023-11-30 19:19:41 24 4
gpt4 key购买 nike

如何在此示例中加入 LINQ 选择中的对象(也接受 C# 变体):

Class Room
Public Area As Integer
End Class

Class RoomPair
One As Room
Two As Room
End Class

Dim pairs as List(Of RoomPair) = mySource.GetRoomPairs()

' Select rooms with Area > 100 from my pairs '
Dim roomsAreaLargerThat100 = From p In pairs Select p.One, p.Two???

' roomsAreaLargerThat100 should be a IEnumerable or a List(Of Rooms) '

最佳答案

展开列表,然后做一个普通的where条件:

pairs.SelectMany(p => new List<Room> {p.One, p.Two}).Where(r => r.Area > 100)

关于c# - 在 LINQ 表达式中加入对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8523712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com