2

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 properties 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?

1
  • 1
    did you try select AuditUser.ToList(); ? Commented Jul 26, 2011 at 17:23

1 Answer 1

7
 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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.