Monday, August 3, 2009

int[] myArray = {2, 4, 5, 6, 43, 432, 3, 94, 2};
Response.Write("Il valore più alto è: " + getMax(myArray));
}
private int getMax(int[] myArray)
{
int massimo = 0;
foreach (int valore in myArray)
if (valore > massimo)
massimo = valore;
return massimo;
}



OR you can try



public void getMaxIndex(int[] thearray)
{
int k =0;
foreach (int j in thearray)
{

if (j > k)
k = j;

}
Console.WriteLine("The max number in array is:{0}",k);

}