65.9K
CodeProject is changing. Read more.
Home

The Elegant Art of Programming

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.67/5 (3 votes)

May 15, 2012

CPOL
viewsIcon

11948

This is an alternative for "The Elegant Art of Programming"

Even simpler:

if ( (new HashSet<double> ( myList )).Count == 1 ) ...

Your code pretty much devolves to this anyway.

On the other hand, the first example you provide is probably more efficient, mainly due to the short-circuit. And if you put it in a library function, you just call it and then there's no concern about elegance.