简体   繁体   English

选择返回真/假值的集合,而不是匹配条件的对象列表

[英]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.

相关问题 如何指定多维数组的内容和 select 对象匹配列表中的条件? - How can I specify the contents of a multidimensional array and select objects matching the criteria from a list? 对象的通用列表包含返回 false - generic list of objects contains short returning false Linq Any返回true,尽管集合中的所有值均为false - Linq Any returns true despite all values in the collection being false 当假定为false时,List.Any()返回true - List.Any() returning true when false was expected 具有相同属性值的集合中的 Select 个对象 - Select objects from a collection with same property values 如何根据子集合中的值 select 对象? - How to select objects based on values in sub collection? Linq:如何为相应的布尔值选择某些文本“ True”或“ False”? - Linq: how to select certain text “True” or “False” for corresponding boolean values? 匹配列表集合中的值和C#中DataTable行中的值 - Matching values in a list collection and values in the DataTable row in C# 使用LINQ在绑定列表中选择与条件匹配的对象? - Select objects in binding list that match criteria using LINQ? Html.checkbox 控件表单集合值带有一些额外的真假值 - Html.checkbox control form collection values are getting with some extra true false values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM