0

I'm a beginner learning C# and I'm currently trying to study how to use the keyboard directional arrow keys to navigate between different arrays in a multidimensional array.

I'm trying to work with a 3x3x3 dimensional array (cube array) and I want to use the arrow keys to navigate between each array and display the contents in that array.

I've already went ahead and filled up the arrays with placeholder data (my array is a

 string [,,] Array = new string[3,3,3]

and I filled it up with names of fruits, for example

 Array[0,0,0] = "apple";

All I need is to be able to navigate to each array using arrow keys (left, down, up, right) and display each of the fruit contents of the Array.

I've been reading around and I think the best option for me would be to use the Switch Case

switch(arrayContents)
{
  case 1: ....

  case 2: .....
}

but I don't know how to incorporate the arrow key presses into this. Any help would be appreciated.

Thanks.

EDIT:

I'm working on a console-based app. I'm using Visual Studio. I just want something like array pointers in C++.

Basically, what I want is (if it's possible) to use the arrow keys on the keyboard to navigate between arrays in a 3D cube array and display their contents.

For example, if

 Array[0,0,0]="apple"; 

contains "apple" and

 Array[0,0,1]="orange"; 

contains "orange", pressing the Right Arrow key would "move" the pointer to the array on the right-side and the display would change from "apple" to "orange"

I haven't gotten into WinForms yet, would it be easier to do this via Winforms? If so, how can I go about it. Like I said, I'm only a beginner in C# programming.

5120bee
  • 689
  • 1
  • 14
  • 36
  • Huh? I don't understand. Is this a console app? Winforms? Wpf? What should be displayed when an arrow is pressed? I'm confused as to what you want. Consider adding more details – dmeglio May 06 '16 at 01:26
  • do you have a user interface? WPF? WinForms? ASP?-- If it's one of those you can use the [previewkeydown](https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.previewkeydown(v=vs.110).aspx) event to update the GUI select an object from the array etc. – Felix Castor May 06 '16 at 01:30
  • This is a console-based app. I'm using Visual Studio. I just want something like array pointers in C++. Basically, what I want is (if it's possible) to use the arrow keys on the keyboard to navigate between arrays in a 3D cube array and display their contents. For example, if Array[0,0,0]="apple" contains "apple" and Array[0,0,1]="orange" contains "orange", pressing the Right Arrow key would "move" the pointer to the array on the right-side and the display would change from "apple" to "orange". I haven't got into Winforms yet -- is it required to be able to perform a function like this? – 5120bee May 06 '16 at 01:53
  • how using two dimensions (Up-down, left-right) are you intending to navigate in three dimensions? I still don't understand what you want. Since you seem to indicate you know how to do this in c++ why not show c++ code then we can help you recreate it in c# – dmeglio May 06 '16 at 02:23

1 Answers1

0

There is no equivalent of C++ array pointers in C#.

You don't need a switch statement.

You just use indexes into the array.

So if you had a 3 dimensional array, you'd probably have 3 indexes.

Let's call the indexes x, y, z.

Manipulate these indexes appropriately based on the arrow key presses, then access the array using them, to display the contents of the array:

var output = Array[x,y,z];

display output;

Craig M
  • 81
  • 4