title: Creating a two-dimensional array
body: <p>I am trying to create a two dimensional array and I am getting so confused. I was told by a coworker that I need to create a dictionary within a dictionary for the array list but he couldn't stick around to help me. </p>
  
  <p>I have been able to create the first array that lists the the programs like this </p>
  
  <pre><code>+ project 1
  + project 2
  + project 3
  + project 4
  </code></pre>
  
  <p>The code that accomplishes this task is below-</p>
  
  <pre><code>var PGList = from x in db.month_mapping
               where x.PG_SUB_PROGRAM == SP 
               select x;
               //select x.PG.Distinct().ToArray();
  
  var PGRow = PGList.Select(x =&gt; new { x.PG }).Distinct().ToArray();
  </code></pre>
  
  <p>So that takes care of my vertical array and now I need to add my horizontal array so that I can see the total amount spent in each accounting period. So the final output would look like this but without the dashes of course.</p>
  
  <pre><code>+ program 1-------100---200---300---400---500---600---700---800---900---1000---1100---1200
  + program 2-------100---200---300---400---500---600---700---800---900---1000---1100---1200
  + program 3-------100---200---300---400---500---600---700---800---900---1000---1100---1200
  + program 4-------100---200---300---400---500---600---700---800---900---1000---1100---1200
  </code></pre>
  
  <p>I have tried to use a foreach to cycle through the accounting periods but it doesn't work. I think I might be on the right track and I was hoping SO could provide some guidance or at the very least a tutorial for me to follow. I have posted the code that I written so far on the second array below. I am using C# and MVC 3. You might notice that their is no dictionary within a dictionary. If my coworker is correct how would I do something like that, I took a look at this question <a href="https://stackoverflow.com/questions/433372/c-using-dictionary-as-a-key-in-other-dictionary">using dictionary as a key in other dictionary</a> but I don't understand how I would use it in this situation. </p>
  
  <pre><code>Dictionary&lt;string, double[]&gt; MonthRow = new Dictionary&lt;string, double[]&gt;();
  
  double[] PGContent = new double[12];
  
  string lastPG = null;
  
  foreach (var item in PGRow)
  {
      if (lastPG != item.PG)
      {
          PGContent = new double[12];
      }
  
  
      var MonthList = from x in db.Month_Web
                      where x.PG == PG
                      group x by new { x.ACCOUNTING_PERIOD, x.PG, x.Amount } into pggroup
                      select new { accounting_period = pggroup.Key.ACCOUNTING_PERIOD, amount = pggroup.Sum(x =&gt; x.Amount) };
  
      foreach (var P in MonthList)
      {
          int accounting_period = int.Parse(P.accounting_period) - 1;
          PAContent[accounting_period] = (double)P.amount;
          MonthRow[item.PG] = PGContent;
          lastPG = item.PG;
      } 
  </code></pre>
  
  <p>I hope I have clearly explained my issue, please feel free to ask for any clarification needed as I need to solve this problem and will be checking back often. Thanks for your help!</p>