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

Report
Posts
3
Registration date
Thursday March 7, 2019
Status
Member
Last seen
March 14, 2019
-
 Blocked Profile -
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 !

1 reply

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.


Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!