Link to home
Start Free TrialLog in
Avatar of Adnan
AdnanFlag for Norway

asked on

How to declare tree-dimentional array list

Hi

How can I declare a list with 3 dimensional array with prices like showed in a table below:

User generated image
Avatar of Rgonzo1971
Rgonzo1971

HI,

pls try
        int[, ,] array3D = new int[,,] { { { 1, 1, 50 }, { 1, 2, 50 } , { 1, 3, 50 }, { 1, 4, 50 }, { 1, 5, 50 } }, 
                                 { { 2, 1, 50 }, { 2, 2, 50 } , { 2, 3, 50 }, { 2, 5, 50 }, { 2, 5, 50 } } };

Open in new window

Regards
int[,] items = new int[2,10];

items[0,0]=1;
items[1,0]=1;
items[2,0]=50;
...
items[2,10]=60;
Hi

3d data corrected
        int[, ,] array3D = new int[,,] { { { 1, 1, 50 }, { 1, 2, 50 } , { 1, 3, 50 }, { 1, 4, 50 }, { 1, 5, 50 } }, 
                                 { { 2, 1, 55 }, { 2, 2, 55 } , { 2, 3, 55 }, { 2, 5, 55 }, { 2, 5, 55 } } };

Open in new window

and 2D
        int[,] array2D = new int[,] { { 50, 50, 50, 50, 50 }, { 55, 55, 55, 55, 55 } , { 60, 60, 60, 60, 60 } };

Open in new window

Avatar of Adnan

ASKER

Thanks a lot for the response...

Array list have to be based on 1-10 kilos on one axis and 1-5 packages on other axis, 3 axis with the price

User generated image
Price for each package starts at 50,- krones for one kilogram and continues upward by 5,- krones extra per. kilo. Assume that there is only whole kilogram.
then try (array is Zero based)

        int[,] array2D = new int[35,5] ;
        for (int i = 0; i <= array2D.GetUpperBound(0);i++)
        {
            for (int j = 0; j <= array2D.GetUpperBound(1); j++)
            {
                array2D[i, j] = 50 + (5 * (i));
            }
        }  

Open in new window

Price for each package starts at 50,- krones for one kilogram and continues upward by 5,- krones extra per. kilo. Assume that there is only whole kilogram.

Why do you need a array, when it could be calculated as 50 + 5 * weight?
Avatar of Adnan

ASKER

Maybe I do not need an array and calculate as you say, but I have to display a list with correct prices in a GUI, html table or GRID...
Can you please give us a concise and complete description of your problem?

Just to make it clear: "GUI, html table or GRID..." isn't really exact.
Avatar of Adnan

ASKER

UI  will list up prices in a two-dimensional table based on 1-10 kilos on one axis and 1-5 packages on other axis, and 3 axis with the price....

simple display it in User interface....
Avatar of Adnan

ASKER

just want to display the list.....
Avatar of Adnan

ASKER

int[,] array2D = new int[35,5] ;
        for (int i = 0; i <= array2D.GetUpperBound(0);i++)
        {
            for (int j = 0; j <= array2D.GetUpperBound(1); j++)
            {
                array2D[i, j] = 50 + (5 * (i));
            }
        } 

Open in new window


This code is working fine, only thing is that I have to start from 12345, and not 01235

How can I fix that it declare array starting from 12345?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adnan

ASKER

Hi ste5an

iam using .Net MVC razor with EF.
I will try to test your code, thanks for the response
Avatar of Adnan

ASKER

Thanks a lot for all help :)