Click here to Skip to main content
14,699,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to make for loop in c# that enable me to fill unlimited array?
such as [n,n]?
Posted

for(int i=0; i<n; i++)
  for(int j=0; j<n;++j)
  {
    // Fill your array here
    // someArray[i][j] = "something";
  }

Now what was in it that you failed to try?
   
v2
Hi,

as first: when using a normal array - this can not be of unlimited size. This means that the size must be known before.

If you want to fill a 2 dimensional array you need two nested "for" loops.

Any basic .net tutorial or book should help you here.

Best regards,

JF
   
Comments
Toli Cuturicu 25-Jul-10 9:00am
   
Reason for my vote of 3
Two nested for loops are not really necessary
Toli Cuturicu 25-Jul-10 9:02am
   
for (int i = 0; i < n * n; i++)
arr[i / n, i % n] = ...
JF2015 25-Jul-10 9:47am
   
That may be totally right, but if I would see code like this I would definitely refactor it, since readability of this is almost zero

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900