We help IT Professionals succeed at work.

How to declare tree-dimentional array list

Adnan
Adnan asked
on
125 Views
Last Modified: 2015-12-01
Hi

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

22.PNG
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
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
CERTIFIED EXPERT
Top Expert 2015

Commented:
int[,] items = new int[2,10];

items[0,0]=1;
items[1,0]=1;
items[2,0]=50;
...
items[2,10]=60;
CERTIFIED EXPERT
Top Expert 2016

Commented:
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

Author

Commented:
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

22.PNG
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.
CERTIFIED EXPERT
Top Expert 2016

Commented:
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

ste5anSenior Developer
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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...
ste5anSenior Developer
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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....

Author

Commented:
just want to display the list.....

Author

Commented:
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?
Senior Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi ste5an

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

Author

Commented:
Thanks a lot for all help :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.