如何从其他属性为 True 的 Ilist<T> 中获取一个 属性

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

我正在尝试 select ID 来自 Ilist<T> 其中 2 个布尔属性等于 true

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

但是如果我想 return 和 select 只有 t.ID 其中 t.IsValidt.IsBalance 怎么办?我找不到示例

谢谢

使用Where for the filtering and Select for projection:

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

您还可以使用查询语法:

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