Distinct() with lambda?

前端 未结 18 1161
南旧
南旧 2020-11-22 06:04

Right, so I have an enumerable and wish to get distinct values from it.

Using System.Linq, there\'s of course an extension method called Distinct<

18条回答
  •  野性不改
    2020-11-22 06:25

    If Distinct() doesn't produce unique results, try this one:

    var filteredWC = tblWorkCenter.GroupBy(cc => cc.WCID_I).Select(grp => grp.First()).Select(cc => new Model.WorkCenter { WCID = cc.WCID_I }).OrderBy(cc => cc.WCID); 
    
    ObservableCollection WorkCenter = new ObservableCollection(filteredWC);
    

提交回复
热议问题