![]() |
| | #1 |
| Registered User Join Date: Sep 2008
Posts: 62
| 3D array initializer list Code: int [,] 2D = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
But when it comes to 3D array, I am so confused. Take this one for example, which I stole it from MSDN. Code: int[, ,] array3D = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } }}
|
| kenryuakuma is offline | |
| | #2 |
| Registered User Join Date: Jun 2008
Posts: 1,134
| edited Last edited by C_ntua; 10-30-2009 at 08:38 AM. |
| C_ntua is offline | |
| | #3 |
| Registered User Join Date: Jun 2008
Posts: 1,134
| It is a bad example, but it is a 2x1x3 array. If it was a 1x2x3 it would be Code: {{ { 1, 2, 3 } , { 4, 5, 6 } }}
Code: { { { 1, 2, 3 } }, { { 4, 5, 6 } }}
Then you can tell that each something is a 1x3 |
| C_ntua is offline | |
| | #4 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,122
| I'd format it like this, for easier reading: Code: var x = new int[,,]
{
//A
{
//A.1
{
1,2,3,4,
},
//A.2
{
5,6,7,8,
},
//A.3
{
9,0,1,2,
},
},
//B
{
//B.1
{
3,4,5,6,
},
//B.2
{
7,8,9,0,
},
//B.3
{
1,2,3,4,
},
},
};
//Outer (A, B)
for(var i1 = 0; i1 < 2; i1++)
{
//Middle (1, 2, 3)
for(var i2 = 0; i2 < 3; i2++)
{
//Inner
for(var i3 = 0; i3 < 4; i3++)
{
var v = x[i1,i2,i3];
}
}
}
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #5 |
| Registered User Join Date: Sep 2008
Posts: 62
| Thanks so much for helping. But one more question. I assume this is not possible, but I really wanna know if that really works. Is it possible to initialize and declare a 3d array like this: int[, ,] array3D = new int[,,] {{{ 1, 2, 3 }}, {{ 4, 5, 6 }, { 8,0,7 }}} |
| kenryuakuma is offline | |
| | #6 | |
| Registered User Join Date: Jun 2008
Posts: 1,134
| Quote:
| |
| C_ntua is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting a node in linked list | BoneXXX | C Programming | 18 | 12-17-2007 12:30 PM |
| instantiated from here: errors... | advocation | C++ Programming | 5 | 03-27-2005 09:01 AM |
| Quick question about SIGSEGV | Cikotic | C Programming | 30 | 07-01-2004 07:48 PM |
| Linked List Help | CJ7Mudrover | C Programming | 9 | 03-10-2004 10:33 PM |
| singly linked list | clarinetster | C Programming | 2 | 08-26-2001 10:21 PM |