Find Highest Value in Array

Hello,

I have an array that stores a bunch of int. What I want to do, is to print the element with the highest int.

How would I go about doing that?

var turretArray : int [];

In C# you can use System.Linq along with Max():

int[] foo = {3, 6, 8, 33, 1, 10};
Debug.Log (foo.Max());

Make a function that loops through the array and stores the highest value:

function Start () {
	var foo = [3, 6, 8, 33, 1, 10];
	Debug.Log (MaxValue(foo));
}

function MaxValue (intArray : int[]) : int {
	var max = intArray[0];
	for (i = 1; i < intArray.Length; i++) {
		if (intArray *> max) {*

_ max = intArray*;_
_
}_
_
}_
_
return max;_
_
}*_

var max = Mathf.Max(myArray);

You would iterate through the array, keeping the current high value in an outside variable.

var highest: int = -999;
var turretArray : int [];

//populate array
foreach (int i in turretArray){
    if (turretArray *> highest)*

highest = turretArray*;*
}
or somesuch. I don’t use C# on a regular basis, but that’s the gist of it.

var IntArray : int = [0, 5, 10, 2, 32, 26, 54, 58, 90, 22, 34, 55];
function FindMaxValue()
{
var Max : int;
//Declaring Variables Without Defining Type(Ex. var EX = 0) Compiles Faster For
//Some Reason, if You Wanted A Float Value, var EX = 0.0, an int array would be
//var IntArray = [0];
for(var i = 0; i < IntArray.Length)
{
Max = IntArray[0];
if(IntArray > Max)
{
Max = IntArray*;*
}
}
print("Max Value: "+Max);
}