-1

I have four arrays each of size two, and i want to put them all in one array, so the when it J is = 1, it should use the first array, if J = 2, it should access the second array and so on.

    char[] p1Arr = new char[2];
            char[] p2Arr = new char[2];
            char[] p3Arr = new char[2];
            char[] p4Arr = new char[2];
            char[][] pArrays = new char[][] {p1Arr, p2Arr, p3Arr, p4Arr};   //i tried to create this array of the four arrays

//The four arrays values        
            p1First = p1.Substring(0, 1);
            p1Arr[0] = Convert.ToChar(p1First);
            p1Second = p1.Substring(1, 1);
            p1Arr[1] = Convert.ToChar(p1Second);

            p2First = p2.Substring(0, 1);
            p2Arr[0] = Convert.ToChar(p2First);
            p2Second = p2.Substring(1, 1);
            p2Arr[1] = Convert.ToChar(p2Second);


            p3First = p3.Substring(0, 1);
            p3Arr[0] = Convert.ToChar(p3First);
            p3Second = p3.Substring(1, 1);
            p3Arr[1] = Convert.ToChar(p3Second);

            p4First = p4.Substring(0, 1);
            p4Arr[0] = Convert.ToChar(p4First);
            p4Second = p4.Substring(1, 1);
            p4Arr[1] = Convert.ToChar(p4Second);

           //Loop on the four arrays and their two values
            for (int j = 0; j < 4; j++)
            {
                pArrays[][] = pArrays[0][]; //my problem is here, how can i access each array??

                //get the first array....fourth.
                for (int i = 0; i < 2; i++)
                {
                    //loop on the values of the first array...fourth.
                    if (i == 0)
                    {
                        if (pArrays[j][i] == 0)
                        {
                            row = 0;
                        }
                   ........
                  }

I can't get to access each array in the array of arrays, how can i fix that?

1 Answers1

1

You could probably simplify what you are doing

char[][] pArrays =
   {
      p1.ToCharArray(0, 2),
      p2.ToCharArray(0, 2),
      p3.ToCharArray(0, 2),
      p4.ToCharArray(0, 2)
   };

// to looped the arrays
for (int j = 0; j < 4; j++)
{
   // to access the original array
   var originalArray = pArrays[j];

   // to loop the elements
   for (int i = 0; i < 2; i++)
   {
      // to access the elements
      // pArrays[j][i]
      // originalArray[I]
   }
}
TheGeneral
  • 79,002
  • 9
  • 103
  • 141