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);
谢谢,我很感谢任何关于为什么这不起作用的帮助或建议。
I am using a lamda expression to filter a query.
Basically, I have lines that are composed of segments and these segments are marked as deleted, inserted or null.
What I want returned are segments that have been marked as deleted but whose any sibling IS NOT marked as deleted. As an example,
Line: "Soylent Green is people!" Broken into 2 segments...
Segment 1: "Soylent Green " (marked as deleted)
Segment 2: "is people!" (not marked as deleted)
Should return me Segment 1. But the next example,
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)
Should not return any segments. See code below:
return seg => seg.ModType == Deleted &&
seg.Line.Segments.Any(segs => segs.ID != seg.ID &&
segs.ModType != Deleted);
Thanks and I appreciate any help or suggestion as to why this is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想它会是这样的:
I'd think it would be something like:
使用Where()而不是Any(),它将返回一个IEnumerable对象。正如 Jon 所说,Any() 返回一个布尔值。
Instead of Any(), use Where(), which will return you an IEnumerable object. Like Jon says, Any() returns a boolean.
由于 ModType 可为空,因此它没有返回我所期望的内容。代码应该是...
Since ModType is nullable, it did not return what I was expecting. The code should be...