First GroupBy MyObject. Order and then determine if Any of the groups have more than one member: bool be = myObjectList. GroupBy(x => x.
Order) . Any(g => g.Count() > 1); // be is true is there are at least two objects with the same Order // be is false otherwise.
Bool hasDuplicates = myObjectList. Count > new HashSet(myObjectList. Select(x => x.
Order)).Count.
Not a pure Linq-To-Objects-Solution, but how about: var ordersList = new List(myObjectList. Select(obj => obj. Order); bool allUnique = ordersList.
Count == new HashSet(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.
You could improve performance by avoiding the intermediate List. The HashSet constructor can take an IEnumerable directly. – LukeH Jan 29 '10 at 15:20 What has O(n^2) lookups?
– Jason Jan 29 '10 at 15:21 @Luke, yap thanks, I overcomplicating. Of course the ordersList will always have the same count as the original list. – herzmeister Jan 29 '10 at 15:37 1 @Jason, I think I originally saw some answers posted with some Count() statements nested.
And Count() in Linq is definately evil. – herzmeister Jan 29 '10 at 15:38.
Bool allUnique = ordersList. Count == ordersList. Select(o => o.
Order).Distinct().Count().
The Count() method takes a predicate, so you would do something like this: if(myObjectList. Count(x => x. Order == 1) >= 2) { // Do something }.
That only checks if there is a duplicate with MyObject. Order equal to 1. It ignores the possibility of there being a duplicate with MyObject.
Order equal to any other int. – Jason Jan 29 '10 at 14:44 This would only test whether there are multiple objects with Order==1, not if there are two objects with the same (unknown) value. – Hans Kesting Jan 29 '10 at 14:45.
Var ordersList = new List(myObjectList. Select(obj => obj. Bool allUnique = ordersList.
Count == new HashSet(ordersList).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.