|
Hi, I'm trying to make a ranking with the best scores. All scores are stored in an array, but when I try to sort the values to make a ranking, Unity returns the following message: Assets/Scripts/Test.cs(12,29): error CS1501: No overload for method I looked for answers in Unity Answers, Unify Community, MSDN Library, but still doesn't work. Is possible sort values in Unity/C#? My Code: and another try: Thanks guys!!
(comments are locked)
|
|
This works just fine.
I read this page of MSDN many times, but I don't no how can I put this code in Unity. I tried your code, but the program returns this: The name `Array' does not exist in the current context
Jun 26 '11 at 07:15 PM
zlabs
Have you seen:
Jun 26 '11 at 07:19 PM
Marnix
Man, I'm sorry!! I thought that System; it was the same thing that System.Collections; of unity. Now everything works fine!! Thank you very much! :D
Jun 26 '11 at 07:34 PM
zlabs
(comments are locked)
|
|
Well, what imports do you have? You need to get System.Linq in order to use IEnumerable.Sort() Edit: After some research, try using IEnumerable.OrderBy instead. Hi, macfanpro I'm newbie, and I don't understand how I can use IEnumerable.Sort(), but I go to research. Thanks for your answer!
Jun 26 '11 at 06:55 PM
zlabs
Just copy in the line I edited with. For ease, use this:
Jun 26 '11 at 07:01 PM
ckfinite
Jun 26 '11 at 07:03 PM
Marnix
You did add the line
Jun 26 '11 at 07:39 PM
ckfinite
Oh, I made a mistake. OrderBy doesn't change the source array, it returns an enumerable that is sorted. Try this:
Jun 26 '11 at 08:15 PM
ckfinite
(comments are locked)
|

I just wanted to comment for other people that run across this Q: you shouldn't be using Arrays in C# for this kind of table data. ArrayLists or even better; List T are much better for non-static data. For ListT you do need to add using System.Collections.Generics
List is the current recommended List data structure. However, if you have a REALLY (1Mb+) large list of data, and it's length doesn't change, arrays are your best choice. The list system adds some overhead, and over big data sets you will have slowdowns.
Arrays are always faster than Lists, even if the data set isn't large, especially for types such as int. (Accessing
int[]is 6X faster thanList<int>, but with complex types such as GameObject, there's not much difference.) If the array doesn't need to change size, then use arrays and not Lists. Especially don't use ArrayList, unless the array contains data of more than one type, but that's something you'd rarely do.Lists can actually work for multi-type data, as long as the data is all subclassed and polymorphic, but that comes down to having a single type, just through a layer of abstraction.