Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multidimensional Array

Status
Not open for further replies.

akaballa

Programmer
Feb 2, 2007
8
CA
Hi,

While creating this program i keep gettin this error that says: "Invalid Rank Specifier: expected ',' or ']'"

using System;

class New
{
public static void Main()
{
int[,,] myArray = new int[,,]
{
{200, 100, 100},//problem here
{100, 200, 2345},//problem here
{244, 3435, 443},//problem here
{4232, 342, 567},//problem here
{434, 344, 1112},//problem here
};
int i;
int j;
int z;

for (i = 0; i < 5; i++)
{
for (j = 0; j < 5; j++)
{
for (z = 0; z < 5; z++)
{
Console.WriteLine(myArray[i, j, z]);
}
}
}
}
}
 
You must declare the array like:

Code:
int[, ,] myArray = new int[,,] 
{ 
    { 
        { 2, 3, 4 }, { 4, 5, 6 }, { 6, 7, 8} 
    }, 
    { 
        { 6, 7, 8 }, { 8, 9, 10 }, { 10, 11, 12 } 
    } 
};

I suggest to take a look at this MSDN tutorial about arrays in C#:
Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top