Hi Guys
NP67 Dimensional Array
By means of counting the elements (below program) it is possible to predict number of elements in one-dimensional array prior to the execution of the program. And elements can be assigned as follows:
empID[0] = 15
empID[1] = 20
empID[2] = 5
In the three dimensional array though Length is 4 (below program) how can predict number of elements in. And how can elements be assigned. Anyone knows please explain.
Thank you
using System;
class MainClass
{
public static void
{
int[] empID = new int[] { 15, 20, 5, };
int[, ,] empArray = new int[1, 2, 2];
Console.WriteLine("empID.Length = " + empID.Length);
Console.WriteLine("empArray.Length = " + empArray.Length);
}
}
/*
empID.Length = 3
empArray.Length = 4
*/
Posted Dec 6, 2007, 1:25 AM
Thank you for the explanation, Alan.
AlanPosted Dec 5, 2007, 2:54 PM
For some reason that link doesn't work but, from your description, in the same way that a two dimensional array can be used to represent points on a rectangular surface, I imagine that a three-dimensional array is being used to represent points on the surface of a cube i.e. the third dimension represents one of the six sides.
I'd have thought that, strictly speaking, a rectangular array was just a two dimensional array but the C# Specification does in fact use the term rectangular array to represent any non-jagged multidimensional array, so I guess we can consider that as 'official' :)
Posted Dec 5, 2007, 9:15 AM
Hi Guys
http://en.csharp-online.net/All_about_Arrays_in_CSharp%E2%80%94Instantiating_a_One-Dimensional_or_Rectangular_Array
In the above website Figure 14-5 shows the diagram of a cube to explain three-dimensional array. Cube edges representing the dimensions. My problem is, if
Dimension of the array exceeds the number of available edges in the cube how to represent in a cube. In such a situation if it is appropriate to call rectangular array.
Anyone knows please explain.
Thank you
Posted Dec 1, 2007, 9:03 AM
Thank you for the explanation, Alan.
AlanPosted Dec 1, 2007, 8:00 AM
In general if you have a 3 dimensional array, such as the one below, where x,y and z are positive integers:
int[, ,] empArray = new int[x, y, z];
then the number of elements in the array is x * y * z.
So, in the case of this array:
int[, ,] empArray = new int[1, 2, 2];
there are 1 * 2 * 2 = 4 elements
You could set these elements 'manually' as follows:
empArray[0, 0, 0] = 20;
empArray[0, 0, 1] = 30;
empArray[0, 1, 0] = 40;
empArray[0, 1, 1] = 50;
If the initial values of each element are a function of x, y and z, then larger arrays would normally be initialized using three nested 'for' loops.