I am having trouble wrapping my head around the concept of an array with more than two dimensions, why you would need one, and how you would use it.
For example, how would you go about representing the following data in a multidimesional array?
Sex: Male | Female
Hair Color: Blond | Brunette | Black
Eye Color: Blue | Brown | Green | Hazel
Instinct is telling me that I should create an array as so:
string[,,] personAttributes = new string[2,3,4]
Please show how you would you fill up this array without a loop, and then with a loop. Any expansion on concepts and usage appreciated.
I’m not going to touch your personAttributes example because I don’t think a 2D array is a good idea, let alone 3D (personally I would use an array of structs).
However, multidimensional arrays are very useful when you have some kind of orthogonal data space (i.e. you have several “choices” which are independent of each other).
For instance, if you’re storing the response times of 20 people over 10 tests, where each test is repeated 3 times, and the whole thing is done once a month for 12 months, you might have an array like this: