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

Closed
salmamk27 Posts 3 Registration date Thursday March 7, 2019 Status Member Last seen March 14, 2019 - Mar 14, 2019 at 11:01 AM
 Blocked Profile - 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 !
Related:

1 response

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.


0