I have a list called com, which contains a bunch of integers. I need to check the list to make sure that each integer only exists once in the list. So if:
com{1,2,3,4,1,3}
I need have some code to check that 1 is represented twice as well as 3. This is my best guess on how to solve it:
for (int j = 0; j < com.Count; j++)
{
if (com.Contains(com[j]))
{
lion += 1;
}
else
{
lion = 0;
}
}
But it doesn't work. Can anybody out there help me??
Here's a simple, but probably not that efficient way using LINQ:
using System.Linq;
...
bool containsRepeats = com.Count() != com.Distinct().Count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With