0

trying to understand all this syntax

public class TwoDimensions { static void Main() { int[,] twodim = new int[,] { { 1, 2, 3 }, { 9, 8, 7 } }; int dim1 = twodim.GetLength(0); int dim2 = twodim.GetLength(1); WriteLine("Dimension 0 contains {0} elements.", dim1); WriteLine("Dimension 1 contains {0} elements.\n", dim2); for (int i1=0; i1 < dim1; i1++) { for (int i2=0; i2 < dim2; i2++) { WriteLine("twodim[{0},{1}] = {2}", i1, i2, twodim[i1,i2]); } } ReadLine(); This is my for loop code for a C# project I am learning in a tutorial. What does is the below code doing? I understand everything else. Thanks for help. WriteLine("twodim[{0},{1}] = {2}", i1, i2, twodim[i1,i2]);

18th Nov 2019, 3:25 PM
Making A Change
Making A Change - avatar
3 ответов
+ 2
WriteLine("twodim[{0},{1}] = {2}", i1, i2, twodim[i1,i2]); that line is for printing the values of the twodim array. the number that are inside {} are like place holders for the values in the order they appear after the " ". it's a way of displaying variables inside of strings without using + sign. {0} holds the value of i1 {1} holds the value of i2 {2} holds the value of twodim[i1, i2] if you change the order of variables they will show in different places. ex: WriteLine("twodim[{0},{1}] = {2}", i2, i1, twodim[i1,i2]); now the places of i1 and i2 are switched when they are printed. another thing, think of twodim[i1, i2] as one value. for the above example. if i1 = 0 and i2 =0 twodim[i1,i2] equals 1. because that is the value of [0, 0] in the array.
18th Nov 2019, 5:13 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
I don't know if that explains it all. ex: when i1 = 0 and i2 = 0 the output will be: twodim[0, 0] = 1
18th Nov 2019, 5:22 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Your explanation is correct and easy to understand thanks
18th Nov 2019, 6:38 PM
Making A Change
Making A Change - avatar