0

I have a List<Tuple<int, string>>. I want to get a bool indicating whether there is a match on any of the int values. So for example:

{1, "Yada"}, {2, "Data"} returns false
{1, "Yada"}, {1, "Data"} returns true

Can it be done?

magnusarinell
  • 1,127
  • 14
  • 22

2 Answers2

1

Just group by that value and see if any groups have more than one item:

bool hasDupes =
    list.GroupBy(t => t.Item1)
        .Any(g => g.Count() > 1)
D Stanley
  • 149,601
  • 11
  • 178
  • 240
1

Yes it can be done by grouping:

bool match = list.GroupBy(tuple => tuple.Item1, t => t).Any(group => group.Count() > 1);
René Vogt
  • 43,056
  • 14
  • 77
  • 99