开发者

Collection of unique SelectListitems from list of non-unique SelectListitems using linq

开发者 https://www.devze.com 2023-04-04 00:49 出处:网络
I am 开发者_Python百科having the hardest time coming up with a methodology to take a list of non-unique Selectlistitems and come out with a list of unique SelectListItems.I am attempting to use linq t

I am 开发者_Python百科having the hardest time coming up with a methodology to take a list of non-unique Selectlistitems and come out with a list of unique SelectListItems. I am attempting to use linq to do this... The code for what I tried was this

    var queryResults =
    from p in PatientList
    group p by p.Value into g
    select new SelectListItem { Text= g.Key, Value= g.Max(p => p.Value.Split('|')[1]) };

With this methodology I get the exact same list that I went in with. Now I am a complete novice when it comes to linq. I have done some linq to XML and linq to SQL, but Linq to Collections seems to be alluding...

Any Help possible?


Perhaps you could use Distinct()? It returns unique values from a sequence, optionally using an IEqualityComparer<T> for the uniqueness test.

0

精彩评论

暂无评论...
验证码 换一张
取 消