locked
Initialize 3D Lookup Table RRS feed

  • Question

  • User-1154637791 posted

    I'm trying to create a const lookup table with multiple dimensions; three in this case.  I've found several approaches including, lists, dictionarys, arrays, jagged, etc., but they all seem to nest a lot - nothing really clean.    I'm trying to find an approach like:

    static readonly string[][][] IconCube =
    {
       {[0][0][0] = "~/Icons/ico-1.png"},
       {[0][0][1] = "~/Icons/ico-2.png"},
       {[0][0][2] = "~/Icons/ico-3.png"},
       {[0][1][0] = "~/Icons/ico-4.png"},
    };

    That I can use like:   trv_tree.ImageUrl = IconCube[xOrd][yOrd][zOrd];

    Tuesday, July 23, 2013 10:32 AM

Answers

  • User753101303 posted

    Hi,

    So basically you want to assign explicitely a value to indexed cells. I would suggest for example :

           private static string[,,] IconCubeInitializer {
                get{
                    var r=new string[3,3,3];
                    r[0, 0, 0] = "A";
                    r[0, 0, 1] = "B";
                    r[0, 0, 2] = "B";
                    return r;
                }
            }
            static readonly string[,,] IconCube = IconCubeInitializer;


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2013 11:33 AM

All replies

  • User753101303 posted

    Hi,

    So basically you want to assign explicitely a value to indexed cells. I would suggest for example :

           private static string[,,] IconCubeInitializer {
                get{
                    var r=new string[3,3,3];
                    r[0, 0, 0] = "A";
                    r[0, 0, 1] = "B";
                    r[0, 0, 2] = "B";
                    return r;
                }
            }
            static readonly string[,,] IconCube = IconCubeInitializer;


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2013 11:33 AM
  • User-1154637791 posted

    I like the Property approach, thanks.

    Tuesday, July 23, 2013 1:00 PM