Selection 类有 4 个属性:
public class Selection
{
string IdSelectionType {get; set;}
string Name {get; set;}
decimal? OddValue {get; set;}
bool Visible {get; set;}
}
示例数据
var originalList = new List<Selection>()
{
new Selection() {IdSelectionType = "1", Name = "Under (75.50)", Visible = true},
new Selection() {IdSelectionType = "2", Name = "Under (75.50)", Visible = true},
new Selection() {IdSelectionType = "1", Name = "Under (75.50)", OddValue = 1.840m, Visible = true},
new Selection() {IdSelectionType = "2", Name = "Under (75.50)", OddValue = 1.860m, Visible = true},
};
我想选择一个列表,如果有另一个相同但具有 OddValue 的元素!= null,则丢弃具有 OddValue = null 的元素。
是否有任何 Linq / MoreLinq 运算符可以做类似的事情?
Selections.GroupBy(s =>
new {s.IdSelectionType, s.Name, s.OddValue, s.Visible})
.Select(g => g.First()).ToList();
预期的结果是:
弑天下
MMMHUHU
相关分类