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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -