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?
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?
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)
Yes it can be done by grouping:
bool match = list.GroupBy(tuple => tuple.Item1, t => t).Any(group => group.Count() > 1);