454,666 Members | 1,413 Online
Need help? Post your question and get tips & solutions from a community of 454,666 IT Pros & Developers. It's quick & easy.

# Index out of range

 P: n/a This nested 'for' gives an out of range error on the second pass of the second loop, though it looks allright. Isn't it wierd? for (int tel1=0;tel1<3;tel1++) { for (int tel2=0;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Initializing the second loop with tel2=1 gives immediately an error...I have no clue. Thanks for any hint. Nov 13 '05 #1
6 Replies

 P: n/a How did you allocate the p array? "Francois Vanderseypen" a écrit dans le message de news:3f*********************@reader0.news.skynet.b e... This nested 'for' gives an out of range error on the second pass of the second loop, though it looks allright. Isn't it wierd? for (int tel1=0;tel1<3;tel1++) { for (int tel2=0;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Initializing the second loop with tel2=1 gives immediately an error...I have no clue. Thanks for any hint. Nov 13 '05 #2

 P: n/a The p ArrayList is as follows: ArrayList p=new ArrayList(45); for (int tel1=0;tel1<3;tel1++) { for (int tel2=1;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Setting ..=new ArrayList(200) or ...=new ArrayList() does not change anything. Nov 13 '05 #3

 P: n/a p.Insert(tel1+tel2,tel2); "Francois Vanderseypen" wrote in message news:3f*********************@reader0.news.skynet.b e... This nested 'for' gives an out of range error on the second pass of the second loop, though it looks allright. Isn't it wierd? for (int tel1=0;tel1<3;tel1++) { for (int tel2=0;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Initializing the second loop with tel2=1 gives immediately an error...I have no clue. Thanks for any hint. Nov 13 '05 #4

 P: n/a Francois Vanderseypen wrote: This nested 'for' gives an out of range error on the second pass of the second loop, though it looks allright. Isn't it wierd? for (int tel1=0;tel1<3;tel1++) { for (int tel2=0;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Initializing the second loop with tel2=1 gives immediately an error...I have no clue. Well, how large is the "p" array? If you could post a short but *complete* example which demonstrates the problem, that would help... See http://www.pobox.com/~skeet/csharp/complete.html for what I mean. -- Jon Skeet - http://www.pobox.com/~skeet/ If replying to the group, please do not mail me too Nov 13 '05 #5

 P: n/a Francois Vanderseypen wrote: The p ArrayList is as follows: ArrayList p=new ArrayList(45); for (int tel1=0;tel1<3;tel1++) { for (int tel2=1;tel2<15;tel2++) { p[tel1+tel2]=tel2; } } Ah. I'd assumed p was an array here. (This is why posting a short but complete program to start with saves time.) You need to either fill the list with values first, or possibly create an array and add all of that to the list afterwards. -- Jon Skeet - http://www.pobox.com/~skeet/ If replying to the group, please do not mail me too Nov 13 '05 #6