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:

22.PNG
.NET ProgrammingASP.NETC#

Avatar of undefined
Last Comment
Adnan

8/22/2022 - Mon
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
Jacques Bourgeois (James Burger)

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

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

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

Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
Adnan

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.
Rgonzo1971

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

ste5an

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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Adnan

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...
ste5an

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.
ASKER
Adnan

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....
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
Adnan

just want to display the list.....
ASKER
Adnan

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
ste5an

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Adnan

Hi ste5an

iam using .Net MVC razor with EF.
I will try to test your code, thanks for the response
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Adnan

Thanks a lot for all help :)