napi15
napi15

Reputation: 2402

How to get one property from Ilist<T> where other properties are True

I'm trying to select ID from an Ilist<T> where 2 boolean properties are equal true

myList.Select(t => t.IsValid && t.IsBalance).Distinct().ToList(); 

but if I want to return and select only the t.ID where t.IsValid and t.IsBalance how to do so ? I couldn't find an example

Thank you

Upvotes: 2

Views: 966

Answers (1)

Gilad Green
Gilad Green

Reputation: 37299

Use Where for the filtering and Select for projection:

myList.Where(t => t.IsValid && t.IsBalance).Select(t => t.ID).Distinct().ToList(); 

You can also use query syntax:

var result = (from t in myList
              where t.IsValue && t.IsBalance
              select t.ID).Distinct().ToList();

Upvotes: 7

Related Questions