开发者

Getting one list from another list using LINQ

开发者 https://www.devze.com 2023-03-23 05:54 出处:网络
I\'ve seen the technique of taken a list of ObjectA and converting into a list of ObjectB where the two classes share some similar prope开发者_JAVA百科rties but is there an easier way to do that when

I've seen the technique of taken a list of ObjectA and converting into a list of ObjectB where the two classes share some similar prope开发者_JAVA百科rties but is there an easier way to do that when you're just going from a list of ObjectA to another list of ObjectA?

Basically I want to do ...

 var excv = from AuditedUser in data
    where AuditedUser.IsMarkedForRemoval == false
    select AuditedUser;

... but instead of a var I want the results to form a new List < AuditedUser > .

Is there something super easy I'm just missing?


 var excv = (from AuditedUser in data
    where AuditedUser.IsMarkedForRemoval == false
    select AuditedUser).ToList();

I wrapped your LINQ statement with parens and added the ToList call at the end. Is this what you're looking for?

You could also do the following which is shorter to type and read I think:

List<AuditUser> excv = data.Where(a=>!a.IsMarkedForRemoval).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消