I am collecting integers from a few objects via getcomponent, and putting them into an array, then I want to determine the one with the maximum.
I know how to get the maximum integer in the array. I did it using using System.Linq and myarray.Max(); The only reason I am putting them in the array was for an easy method to compare them to determine this highest number.
But then I still do not know by doing that which one of them had that maximum, which is my whole purpose for doing it.
Do I then need to cycle through them all again with if statements to see which one equalled that maximum?
Ie. If myarray[0]=myarraymax // which belonged to Object A
If that is true, Then print (“the highest number belonged to Object A”), or go to the next If for Object B. My whole purpose is to determine if Object A,B, or C, (sourced from GetComponent), has the highest number.
It just seems a nuisance when I have already pulled the maximum integer out.
Is there a quicker way?
It seems so easy with one line of code to pull out the highest number, so I cannot see why it cannot be as easy to ask which one did it belong?
c# only please.