I am trying to find the biggest number in that struct array with this code:
max=0;
for (i = 1; i <= team.Length; i++)
{
if (team[i].Point > team[max].Point)
{
max = i;
}
It gives me an error that it System.OutOfRangeException
. Please help.
Arrays in C# are 0-based, not 1-based. Change your for
loop:
for (i = 1; i < team.Length; i++)
NOTE: Edited based on feedback by @juharr
Actually since the OP initializes max to 0 it would work with
for (i = 1; i < team.Length; i++)
It's just the<
instead of<=
that fixes it.