[Mono-devel-list] Basic C# help
Kelly Leahy
kellyleahy at swbell.net
Fri Dec 10 16:34:12 EST 2004
Change your <= to < in the while expression.
In C#, arrays are 0 based and so there is no element
<revenue.GetLength(0)> in the array, only 0 .. L-1
where L is revenue.GetLength(0).
Kelly
--- Eric Scott <scottclansman at cwazy.co.uk> wrote:
> Hey;
> I'm newbie to C#, and have been getting an error in
> some simple code I'm
> doing. The error is right after the following while
> loop executes:
>
> int totalrevenue = 0;
> user = 0;
> while(user <= revenue.GetLength(0)) {
> user ++;
> totalrevenue += revenue[user];
> }
>
> Compiles fine, but when I run the exe file I get:
>
> Unhandled Exception:
> System.IndexOutOfRangeException: Array index is out
> of range.
> in <0x00255> Test:Main (string[])
>
> I've fiddled a bit and found that all 50 cycles of
> the loop execute fine
> (The revenue array is 50 values long in one
> dimension), but before the
> next segment of the code executes (Just some
> Console.WriteLine
> commands), the exception occurs.
>
> Sorry to post a newbie question here, but it seemed
> like the most
> fitting place.
> Cheerio,
> ES
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
>
http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list