Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

The Elegant Art of Programming

3.67/5 (3 votes)
15 May 2012CPOL 11.9K  
This is an alternative for The Elegant Art of Programming

Even simpler:

C#
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)