|
-
October 10th, 2011, 06:33 PM
#4
Re: C# - LINQ Lowest Two Values
A more complicated LINQ query would be more suited to select a specific subset of data based on some predicate, but for this, it's better to keep it simple, as suggested above.
Alternatively you could do something like this:
Code:
Nodes max = Population.Max();
Nodes min = Population.Min();
Population.Remove(min);
Nodes nextToMin = Population.Min();
This way you can avoid sorting, and if you need to perserve the original structure of the list, you can put the min back in. Wow, it rimes!
Aside from that, it's a good idea to try and make your code comply with widespread C# naming conventions - local variables such as Population should use camelCasing, so I would rename that to population instead.
These conventions help both you and us (or any potential team members in a team project) understand the code more quickly. Besides, if you give this application a rest, and then come back some time, you'll be quicker to pick up where you left of if your naming conventions are consistent throughout your work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|