Hey I have a missunderstanding about just one line code about OOP in C#

Posts
3
Registration date
Thursday March 7, 2019
Status
Member
Last seen
March 14, 2019
- - Latest reply: ac3mark
Posts
11969
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
April 19, 2019
- Mar 14, 2019 at 11:16 AM
static void remplir(out int[] tab)
{
tab=null;
string reponse;
bool trouve = false;
int i=0;
while(!trouve)
{
i++;
reponse=console.readline();
if(reponse=="")break;
x=int.parse(reponse);
array.resize(i,ref tab);
tab[i-1]=x;

what I could not understand is
 tab[i-1]=x;  

why i-1 while the dimention became i=1 ??
whan i compile and do tab[i]=x;
thy told me that out of range exception has been generated !
thank you guys for help !
See more 

Your reply

1 reply

Posts
11969
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
April 19, 2019
2467
0
Thank you
I dont think you are using resize correctly. Try hard coding an actual resize value and not a variable to begine with. Also I is an intger in this case not an array. Array resize syntax says ref array for first parameter, and you are referencing I, which is an integer.


Respond to ac3mark