title: Sorting string arrays within a jagged array
body: <p>I'm basically working on a project where I have to read in some files with a large list of values where each row belongs to 1 item. I have managed to read each file into a string array where I then used a jagged array to place the information of each item into rows. The issue I'm having now, is that the project requires me to allow the user to select which set of values they wish to sort the list of items by (quicksort,etc). I was able to implement a quicksort algorithm but I'm finding it extremely difficult (with plenty of research) to find out how I am suppose to keep all the values together during the sort algorithm. 
  For example:
  If the user selected to sort it by the year, my program will sort the years but if I was to save that new sorted list into the jagged array, the other information (time, day, latitude, etc) wont correspond to the same item.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>static void Main(string[] args)
      {
          var lineCount = File.ReadLines(@"C:\path\Year_1.txt").Count();
          List[] Items = new List[lineCount];
  
          string[] year = File.ReadAllLines(@"C:\path\Year_1.txt");
          string[] month = File.ReadAllLines(@"C:\path\Month_1.txt");
          string[] day = File.ReadAllLines(@"C:\path\Day_1.txt");
          string[] time = File.ReadAllLines(@"C:\path\Time_1.txt");
          string[] depth = File.ReadAllLines(@"C:\path\Depth_1.txt");
          string[] timestamp = File.ReadAllLines(@"C:\path\Timestamp_1.txt");
          string[] region = File.ReadAllLines(@"C:\path\Region_1.txt");
          string[] iris_ID = File.ReadAllLines(@"C:\path\IRIS_ID_1.txt");
          string[] latitude = File.ReadAllLines(@"C:\path\Latitude_1.txt");
          string[] longitude = File.ReadAllLines(@"C:\path\Longitude_1.txt");
          StreamReader file = new StreamReader(@"C:\path\Year_1.txt");
          string line = file.ReadLine();
  
          string[][] Array = new string[lineCount][];             
          for (int i = 0; i &lt; lineCount; i++)
              for(int j = 0; j &lt; 10; j++)
              {
                  if (j &lt; 10)
                  {
                      Array[i] = new string[10] { year[i], month[i], day[i], time[i], depth[i], timestamp[i], region[i], iris_ID[i], latitude[i], longitude[i] };
                      Console.WriteLine("Year:\tMonth:\tDay:\tTime:\tDepth:\tTimestamp:\tRegion:\tIris_ID:\tLatitude:\tLongitude:\n{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}", Array[i][0], Array[i][1], Array[i][2], Array[i][3], Array[i][4], Array[i][5], Array[i][6], Array[i][7], Array[i][8], Array[i][9]);
                  }
                  else { j = 0; }
              }                             
  
  
  
  
  
          Console.WriteLine("Please select the option you wish to sort the collection of data by (1 - 10)");            
          Console.WriteLine(" 1. Year\n 2. Month\n 3. Day\n 4. Time\n 5. Depth\n 6. Timestamp\n 7. Region\n 8. Iris_ID\n 9. Latitude\n 10. Longitude");
          int Choice = Convert.ToInt32(Console.ReadLine());
          if (Choice == 1)
          {
              Quicksort(year, 0, lineCount - 1);
  
              // Print the sorted array
              for (int i = 0; i &lt; lineCount; i++)
              {                    
                  Console.Write(year[i] + ",\n");                                        
              }
          }
  public static void Quicksort(IComparable[] elements, int left, int right)
          {
              int i = left, j = right;
              IComparable pivot = elements[(left + right) / 2];
  
              while (i &lt;= j)
              {
                  while (elements[i].CompareTo(pivot) &lt; 0)
                  {
                      i++;
                  }
  
                  while (elements[j].CompareTo(pivot) &gt; 0)
                  {
                      j--;
                  }
  
                  if (i &lt;= j)
                  {
                      // Swap
                      IComparable tmp = elements[i];
                      elements[i] = elements[j];
                      elements[j] = tmp;
  
                      i++;
                      j--;
                  }
              }
              // Recursive calls
              if (left &lt; j)
              {
                  Quicksort(elements, left, j);
              }
  
              if (i &lt; right)
              {
                  Quicksort(elements, i, right);
              }
          }
  </code></pre>