I'm a programming newbie and I just started learning about arrays. What confuses me is the way one can initialize a multidimensional array in C#. And that is because I don't specify the coordinates of each element myself, but C# does it somehow.
More specifically, let's say that I initialize this array:
string[,] names = {
{"Deadpool", "Superman", "Spiderman"}
{"Catwoman", "Batman", "Venom"}
};
Given that in single dimensional array initialization C# starts by placing the first value in element [0], I assume that the same holds true for multi-dimensional arrays too. But doesn't it do the same for each seperate dimension ?This can't be true. Because then it would place "Deadpool" on element [0] of the row, and later it would try to place "Catwoman" on element [0] of the first column. And if that was the case, given that element [0] of the first row is the same element [0] of the first column, "Catwoman" would replace "Deadpool" as both would be written in [0,0]. Yet using a foreach
to write everything on the console, both show up. So how and where does C# place each value, to avoid a value of one dimension overwriting the value of another dimension ?