score:-1

The Count() method takes a predicate, so you would do something like this:

if(myObjectList.Count(x => x.Order == 1) >= 2)
{
    // Do something
}

score:11

First GroupBy MyObject.Order and then determine if Any of the groups have more than one member:

bool b = myObjectList.GroupBy(x => x.Order)
                     .Any(g => g.Count() > 1);
// b is true is there are at least two objects with the same Order
// b is false otherwise

score:1

Not a pure Linq-To-Objects-Solution, but how about:

var ordersList = new List<Order>(myObjectList.Select(obj => obj.Order);
bool allUnique = ordersList.Count == new HashSet<Order>(ordersList).Count;

One would have to test performance of all the approaches presented here. I'd be careful, otherwise you end up quickly with some slow O(n²) look-ups.

score:2

bool hasDuplicates = myObjectList.Count >
    new HashSet<int>(myObjectList.Select(x => x.Order)).Count;

score:1

What about Distinct?

bool allUnique = ordersList.Count == ordersList.Select(o => o.Order).Distinct().Count()

Related Articles