Sunday, May 29, 2011

C#: Another HasDuplicates() for IEnumerable



public static bool HasDuplicates_Version2<T>( this IEnumerable<T> sequence ) {
if ( null == sequence ) {
throw new ArgumentNullException( "sequence" );
}
var set = new HashSet<T>();
return !sequence.All( set.Add );
}

No comments :