Skip to main content
 首页 » 编程设计

c#之是否可以在 Linq.Where() 期间过滤子集合

2024年05月10日34落叶

<分区>

我有一个对象层次结构:

DeathStar.Floors.Departments.Rooms 

目前,我只选择包含部门的楼层,这些部门有一个房间,里面有被机器人恐吓或注入(inject)的反叛败类:

var rebelScum = deathStar.Floors.Where( 
                f=> f.Departments.Any( 
                    d => d.Rooms.Any( 
                        r => r.Occupant.Allegiance  == "Rebel" 
                            && (r.InterrogationState == Interrogation.Intimidation 
                                || r.InterrogationState == Interrogation.FloatyStabbyDroid) 
                        ) 
                    ) 
                ); 

但是,rebelScum 将包含与任何被审讯的反叛渣滓相同部门的空房间。

我能否在此 .Where() 中进行过滤以仅返回已占用的房间?