Determinare il valore massimo di un Array
<%@ Page Language="c#" Debug="true" %>
<HTML>
<HEAD>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
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;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>
Scarica il Codice...
Stampa la pagina