Click here to Skip to main content
15,039,470 members
Articles / Programming Languages / C#
Alternative
Tip/Trick
Posted 18 May 2012

Tagged as

Stats

9.2K views
2 bookmarked

The Elegant Art of Programming

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
21 May 2012CPOL
This is an alternative for "The Elegant Art of Programming"

Introduction

To resume what's the point, the solution should solve a simple problem in the most "elegant" way by using LINQ.

Check the orginial tip to get the point of this alternative Smile | :)

Using the code 

Well, reading the following code should be straightforward :
C++
List<double> myList = new List<double>();
myList.Add(1.0);
myList.Add(2.0);
myList.Add(1.0);
 
bool differs = (myList.Distinct().Count() > 1);
 
Console.WriteLine( "All numbers are " + (differs? "not": "") + " the same.");

License

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

Share

About the Author

Guillaume Leparmentier
Engineer
France France
IT consultant and Project Manager in Paris, specialized in software engineering/design.

He spends most of his time in meetings Smile | :)
He would love to have more time to develop all those ideas/concepts he has in mind.

Comments and Discussions

 
GeneralMy vote of 1 Pin
azweepay21-May-12 3:58
Memberazweepay21-May-12 3:58 
This doesn't work at all. In your example the list has 3 items, the distinct list 2, so it differs. If the list contains 3 1.0's, the original list still has 3 items and the distinct list 1. So it differs, even though it shouldn't.\
GeneralRe: My vote of 1 Pin
Guillaume Leparmentier21-May-12 5:12
MemberGuillaume Leparmentier21-May-12 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.