Click here to Skip to main content
14,773,758 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Create a function that can print a three dimension integer array Array3D. Dimensions information is also passed as integer array Info where Info[0], Info[1] and Info[2] represent the number of elements in first, second and third dimensions

What I have tried:

int[,,] Array3D = new int[1, 2, 3] { { { 1, 2, 3 },
                    { 3, 4, 5 }} };
            for (int i = 0; i < Array3D.GetLength(0); i++)
            {
                for (int j = 0; j < Array3D.GetLength(1); j++)
                {
                    for (int k = 0; k < Array3D.GetLength(2); k++)
                    {
                        Console.Write("{0} ", Array3D[i, j, k]);
                    }
                
                }
Posted
Updated 11-Jan-21 14:48pm
v2
Comments
Richard MacCutchan 11-Jan-21 11:45am
   
What you have tried does not follow the instructions, which clearly state: "Dimensions information is also passed as integer array Info where Info[0], Info[1] and Info[2] represent the number of elements in first, second and third dimensions".

So the first thing to do is to define a method that will accept the appropriate parameters.

Read the question carefully.
Quote:
Create a function that can print a three dimension integer array Array3D. Dimensions information is also passed as integer array Info where Info[0], Info[1] and Info[2] represent the number of elements in first, second and third dimensions

It doesn't look like your code does that.
Quote:
Create a function that can print a three dimension integer array Array3D. Dimensions information is also passed as integer array Info where Info[0], Info[1] and Info[2] represent the number of elements in first, second and third dimensions

Your code doesn't do that either.

So your function - when you write it - needs to accept two parameters: teh array, and a second array describing the first.

You have to read the question, and think about what it wants - rather than just leaping into code, or - more likely - copy'n'paste code that does something similar (you hope) from the internet. You won't learn anything that way!
   
In C# a function is usually called a method, see examples here: C# Methods[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900