C# 3 dimensional array definition issue

Posted by George2 on Stack Overflow See other posts from Stack Overflow or by George2
Published on 2009-03-29T11:41:04Z Indexed on 2010/05/13 12:14 UTC
Read the original article Hit count: 216

Filed under:
|

Hello everyone,

My following code has compile error,

Error 1 Cannot implicitly convert type 'TestArray1.Foo[,,*]' to 'TestArray1.Foo[][][]' C:\Users\lma\Documents\Visual Studio 2008\Projects\TestArray1\TestArray1\Program.cs 17 30 TestArray1

Does anyone have any ideas? Here is my whole code, I am using VSTS 2008 + Vista 64-bit.

namespace TestArray1
{
    class Foo
    {    
    }

    class Program
    {
        static void Main(string[] args)
        {
            Foo[][][] foos = new Foo[1, 1, 1];

            return;
        }
    }
}

EDIT: version 2. I have another version of code, but still has compile error. Any ideas?

Error   1	Invalid rank specifier: expected ',' or ']'	C:\Users\lma\Documents\Visual Studio 2008\Projects\TestArray1\TestArray1\Program.cs	17	41	TestArray1
Error   2	Invalid rank specifier: expected ',' or ']'	C:\Users\lma\Documents\Visual Studio 2008\Projects\TestArray1\TestArray1\Program.cs	17	44	TestArray1


namespace TestArray1
{
    class Foo
    {    
    }

    class Program
    {
        static void Main(string[] args)
        {
            Foo[][][] foos = new Foo[1][1][1];

            return;
        }
    }
}

EDIT: version 3. I think I want to have a jagged array. And after learning from the fellow guys. Here is my code fix, and it compile fine in VSTS 2008. What I want is a jagged array, and currently I need to have only one element. Could anyone review whether my code is correct to implement my goal please?

namespace TestArray1
{
    class Foo
    {    
    }

    class Program
    {
        static void Main(string[] args)
        {
            Foo[][][] foos = new Foo[1][][];
            foos[0] = new Foo[1][];
            foos[0][0] = new Foo[1];
            foos[0][0][0] = new Foo();
            return;
        }
    }
}

thanks in advance, George

© Stack Overflow or respective owner

Related posts about c#

Related posts about arrays