-3

I need to get all duplicates in list. LIst like {1,2,3,4,3} and result must be {3,3}.

nezlobin
  • 1
  • 2

1 Answers1

1

This should work, since you need the list to contain all the duplicate items (i.e. two 3's in your example):

var items = new List<int> { 1, 2, 3, 4, 3 };
var dupes = items.Where(searchFor => items.FindAll(item => item == searchFor).Count > 1);
Rufus L
  • 36,127
  • 5
  • 30
  • 43
  • FindAll does not Exist. There is Find but with exception: "IOrderedEnumerable "does not contain a definition for" Find "and could not find the" Find "extension method that takes the type" IOrderedEnumerable "as the first argument (perhaps using the using directive or the assembly reference)" – nezlobin Apr 10 '17 at 06:34
  • You said you were using a `List`, which does not implement `IOrderedEnumerable`. What type are you *really* using? – Rufus L Apr 10 '17 at 06:43
  • Sorry, I wanted to simplify question. I really use massive: PaidService[] array = { //some instances(id,name,cost)}; and must get name of servises with same cost – nezlobin Apr 10 '17 at 08:53
  • Ok. I guess you'll have to ask the question more precisely...this one is closed now and can't be answered. – Rufus L Apr 10 '17 at 09:04
  • Also, using a `List` is better than a `PaidService[]` 99% of the time, with the added bonus that you can use the answer above to solve your problem. – Rufus L Apr 10 '17 at 09:06