- Home /
Sorting variable names by their values.
Hello there!
What I have here is about 20 variables with more or less different numeric values, and I should somehow sort them from largest to smallest, and return the variable names of three largest values.
Now I have been digging around arrays and hashtables, but I am not sure if these are appropriate for this purpose. I dont seem to have any clue where to start solving this problem, and I would appreciate any pointer to help get back on the right track.
Thank you in advance!
Answer by Jesse Anders · Dec 17, 2010 at 04:09 PM
The .NET library includes various sorting functions (e.g. Array.Sort()) that you can use to sort a container based on specified criteria, and this is probably what you'd want to use. (I'm not sure what you mean about returning the 'names' of the variables, but whatever it is you want to do, you should be able to accomplish it using a 'sort' function and perhaps a custom struct or class.)
Answer by raul corrales · Mar 24, 2011 at 05:24 PM
This works if you are interested http://www.youtube.com/watch?v=3560eDQ8shw
Your answer
Follow this Question
Related Questions
Find gameObject with higher variable 1 Answer
Need recommendation for a sorting method for Enemy distances from Player (Ascending) - C# 1 Answer
How to Integrate a .JSON text array into the program? 1 Answer
Creating a list using a list from another script? 1 Answer
Locking the value of a variable, or something similar 2 Answers