[英]Select returning a collection of true/false values, not a list of objects matching criteria
var data = ...; //IList<MyClass>
var subset = data.Select(x => x.Name != null);
I was expecting this to return all the objects where Name
is not null... instead I get a list of bool values true/false indicating whether that item in the original list matched the test. 我期望这将返回
Name
不为null的所有对象……相反,我得到布尔值true / false的列表,这些值指示原始列表中的该项是否与测试匹配。
Is this normal? 这正常吗?
你想要的是哪里的扩展:
var subset = data.Where(x => x.Name != null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.