c# - How to get duplicate items from a list using LINQ? -
i'm having list<string>
like:
list<string> list = new list<string>{"6","1","2","4","6","5","1"};
i need duplicate items in list new list. i'm using nested for
loop this.
the resulting list
contain {"6","1"}
.
is there idea using linq or lambda expressions?
var duplicates = lst.groupby(s => s) .selectmany(grp => grp.skip(1));
note return duplicates, if want know items duplicated in source list, apply distinct
resulting sequence or use solution given mark byers.
Comments
Post a Comment