I faced the error mentioned in the title when doing my homework, and simply can't find a way to remove it. Here is the method that I have this problem with:

public static double LaskeMiidi(double[] luvut)
{
    double ka = Keskiarvo(luvut);
    double miidi = luvut[0];

    for (int i = 0; i &lt; luvut.Length; i++)
    {
        if (luvut[i] - ka &lt; luvut[i + 1] - ka) // The line error points to!
        {
            miidi = luvut[i];
        }
        else
        {
            miidi = luvut[i + 1];
        }
    }
    return miidi;
}


So basically the problem is that when I say luvut[i + 1], at some point this index might become more than the length of the array is. I just can't figure out any ways to solve this problem, since I'm only a beginner with programming.


Question: Could Apple and Microsoft allow the GPLv3 on their locked-down devices?
Answer: Apple effectively ban any GPL because they only allow redistribution through the store and by registered developers. So if you distribute the GPL to your users they cannot abide by it.

Apple could simply allow any GPL app to be redistributed by any user through a free section of the site - but chose not to. Ironically OSX is based on a free BSD Unix kernel.

Microsoft have an historical objection to "the cancer of open source" and their licence explicitly bans any open source licenced app that requires redistribution of source (ie GPL). This is their right, it's a business decision -  just like banning sales in a particular country. As their position in the market becomes less dominant they might change their mind