I want to check whether some property is unique in an enumerable:
var Prop_is_unique = new[]{
new{Prop="A"},
new{Prop="B"}
};
var Prop_is_not_unique = new[]{
new{Prop="A"},
new{Prop="C"},
new{Prop="B"},
new{Prop="C"} // uh oh
};
Is there an elegant way to check uniqueness of a property with LINQ to objects? Something along the lines of:
Prop_is_unique.IsUnique(x => x.Prop); // returns true
Prop_is_not_unique.IsUnique(x => x.Prop); // returns false
Is there a simple and elegant solution with LINQ to objects or do I have to write my own extension method?