arrays - C# foreach loop take values from outer loop to inner loop -


i have below code.

int[] = new int[] { 8, 9 }; for(int i=0;i<n;i++) {      print i;      int z;      //during first iteration       z=8;      during second iteration      z=9; } 

output should this. during first iteration i=0 , z=8 during second iteration i=1 , z=9

array contains 2 elements. n , number of elements in array same. next loop execute. during first iteration want z value should 8(first element of array ) , second iteration z value should 9. want map 1st element of integer array first iteration of loop , on.

try

for (int = 0; < a.length; i++) // or < n if want {     print i;     int z = a[i]; // line value 1 one, 0, 1, 2, 3 , on... } 

edit 1 -

after seeing comments on other answer, array 'a' turns out dynamic array have size n (which 2)

the revised edition:

int n = 2; int[] = new int[n]; string input = null;  (int = 0; < a.length; i++) // or < n if want {     print i;     input = console.readline();     try {         a[i] = int.parse(input);         console.writeline(string.format(             "you have inputted {0} {1} element",             input,         ));     } catch { console.writeline("non integer input"); -= 1; } } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -