C#Lambda表达式未返回预期结果

我正在使用lamda表达式来过滤查询.

基本上,我有由段组成的行,这些段被标记为已删除,已插入或为空.

我想要返回的是已被标记为已删除但其任何兄弟未标记为已删除的段.举个例子,

Line: "Soylent Green is people!" Broken into 2 segments... 
Segment 1: "Soylent Green " (marked as deleted)
Segment 2: "is people!" (not marked as deleted)

应该返回我的第1段.但是下一个例子,

Line: "Open the pod bay doors Hal!" Broken into 3 segments...
Segment 1: "Open the " (marked as deleted)
Segment 2: "pod bay " (marked as deleted)
Segment 3: "doors Hal!" (marked as deleted)

不应该返回任何细分.见下面的代码:

return seg => seg.ModType == Deleted &&
              seg.Line.Segments.Any(segs => segs.ID != seg.ID && 
              segs.ModType != Deleted);

谢谢,我感谢任何帮助或建议,为什么这不起作用.

最佳答案 我认为它会是这样的:

return s =>  from segment in s.Line.Segments 
             where segment.ModType == Deleted 
                && segment.Line.Segments.Any(segs => segs.ModType != Deleted)
             select segment
点赞