How to Sort Integers and Equal Each One to Another Integer?

I have 7 different integers which change during game. I want to pick the highest integer’s name and display it on the screen as the “1st place: name of the 1st integer” and second highest integer’s name as “2nd place: name of the 2nd integer” etc. How do I do that? I don’t want to write 7! if statements. Isn’T there a method or function for it?

You can put all the int in an array or list and then sort the array and revers it so is high to low.and then you can have an array of string with 1st 2nd etc than loop through the second array and set 1st 2nd etc.

1 Like

Thank you. I put all floats in a list with a name and value, and in Update() I tried to sort them. And oddly enough it nearly worked without errors. Now it sorts them from highest to lowest except it places the 3rd value to the 4th place but every other value is placed correctly.Here is the sorting code:

for (int i = 0; i < partiOranlariList.Count; i++)
        {
            for (int j = i + 1; j < partiOranlariList.Count; j++)
            {
                if (partiOranlariList[j].Oran > partiOranlariList[i].Oran)
                {
                    float tmp = partiOranlariList[i].Oran;
                    string tmpstring = partiOranlariList[i].Ad;
                    partiOranlariList[i].Oran = partiOranlariList[j].Oran;
                    partiOranlariList[i].Ad = partiOranlariList[j].Ad;
                    partiOranlariList[j].Oran = tmp;
                    partiOranlariList[j].Ad = tmpstring;
                }
            }
        }
int x = 2;
        int y = 3;
        int z = 5;
            int[] T = new int[3];
            string[] places = new string[3];
            T[0]= z;
            T[1] =x;
            T[2] =y;
            places[0] = "1st";
            places[1] = "2nd";
            places[2] ="3rd";
            Array.Sort(T);
            Array.Reverse(T);
            for(int i =0;i<places.Length;i++)
            {
                Console.WriteLine(places[i]+" "+T[i].ToString());
            }

I did that on my phone and is working fine maybe you could make similar to this ?

1 Like

Just now I realized I misplaced 3th and 4th places, I changed them and it is working fine now, although your version is way more simple and comfortable to write. I will probably use something like that now on. Thank you.

That’s good .
And simple code simple to debug too

1 Like