简体   繁体   中英

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.

Is this normal?

在此处输入图片说明

你想要的是哪里的扩展:

var subset = data.Where(x => x.Name != null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM