1

I am new to C# but have school project that i am working on and need some guidance. I have multiple arrays which i termed array1, array2, array3 , array4 and so on till array9. Now the user is entering digits into input box and i am splitting the input like 543 into 5 4 3 and i want to dynamically call

array5 array4 array3. So basically show contents of these arrays in console.

string value = input.Text.ToString();

 foreach (string s in Array[value[0]])
    {
    -- will loop through all values of array and out put
    foreach (string s in Array[value[1]])
      {
       -- will loop through all values of array and out put
          foreach (string s in Array[value[2]])
          {
          -- will loop through all values of array and out put
          }
       }
    }

How do i accomplish this ? Please help

4
  • Why are there 9 array variables? The entire point of collections is to eliminate multiplicity from variables. Commented Oct 5, 2014 at 6:40
  • I don't understand either. Are you trying to make an array for each number? Commented Oct 5, 2014 at 6:43
  • Do array or arrays: array[9][n], now you can access to X array, for example array[4][2] = ... Commented Oct 5, 2014 at 6:43
  • @user2864740 Yes those are just array names i used for example. So array will have different items in them like collections which will get selected once user enters the desired numbers. Commented Oct 5, 2014 at 6:45

1 Answer 1

2

Try

var arrays = new List<int[]>(){array1,....,array9};

and then if you have 5, 4, 3 you can call arrays like

arrays[4], arrays[3], arrays[2]
Sign up to request clarification or add additional context in comments.

6 Comments

I did that but it says var the type or namespace cannot be found c#
then read more about what is var ... you have another mistake, I assume you have problem with brackets
This is what i typed var arrays = new List<int[]>{Array2,Array3,Array4,Array5,Array6,Array7,Array8,Array9};
important is, where you typed this code. Are you inside of method or constructor? Probably not. Code more, ask less ;)
Here's my code. Its just frustrating :( 'string[] Array2 = new string[3] { "A", "B", "C" }; string[] Array3 = new string[3] { "D", "E", "F" }; string[] Array5 = new string[3] { "J", "K", "L" }; string[] Array6 = new string[3] { "M", "N", "O" }; string[] Array7 = new string[3] { "P", "R", "S" }; string[] Array8 = new string[3] { "T", "U", "V" }; string[] Array9 = new string[3] { "W", "X", "Y" }; List<int[]> data = new List<int[]> { Array2, Array3, Array4, Array5, Array6, Array7, Array8, Array9 };'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.