title: multiplication of C# lists
body: <p>I am having a brain freeze and just cant figure out a solution to this problem.</p>
  
  <p>I created a class called CustomSet that contained a string list. The class holding a reference to CustomSet stores it as a list.</p>
  
  <pre><code>public class CustomSet : IEnumerable&lt;string&gt;
  {
      public string Name { get; set; }
      internal IList&lt;string&gt; elements;
  
      public CustomSet(string name)
      {
          this.Name = name;
          this.elements = new List&lt;string&gt;();
      }
  
      public IEnumerable&lt;string&gt; Elements
      {
          get
          {
              return elements;
          }
      }
      public IEnumerator&lt;string&gt; GetEnumerator()
      {
          return elements.GetEnumerator();
      }
      IEnumerator IEnumerable.GetEnumerator()
      {
          return GetEnumerator();
      }
  }
  </code></pre>
  
  <p>So what I would like to do is iterate over this list of custom sets to out put a 2d string array where the columns are the number of customSet(s) and the rows are a multiplication of the customSet elements.</p>
  
  <p>As an example, if there were 3 custom sets in the list: 1st had 3 elements, 2nd had 2 elements and 3rd had 3 elements. I would want to output 3 columns and 18 rows (3*2*3). The following code is an attempt at the solution:</p>
  
  <pre><code>CustomSet motion = new CustomSet("Motion");
  motion.Elements.Add("low");
  motion.Elements.Add("medium");
  motion.Elements.Add("high");
  
  CustomSet speed = new CustomSet("Speed");
  speed.Elements.Add("slow");
  speed.Elements.Add("Fast");
  
  CustomSet mass = new CustomSet("Mass");
  mass.Elements.Add("light");
  mass.Elements.Add("medium");
  mass.Elements.Add("heavy");
  
  List&lt;CustomSet&gt; aSet = new List&lt;CustomSet&gt;();
  aSet.Add(motion);
  aSet.Add(speed);
  aSet.Add(mass);
  
  //problem code
  int rows = 1;
  for(int i = 0; i &lt; aSet.Count; i++)
  {
      rows *= aSet[i].Elements.Count;
  }
  
  string[,] array = new String[aSet.Count, rows];
  int modulus;
  
  for (int i = 0; i &lt; aSet.Count; i++)
  {
      for (int j = 0; j &lt; rows; j++)
      {
          modulus = j % aSet[i].Elements.Count;
          array[i, j] = aSet[i].Elements[modulus];
      }
  }
  
  for (int j = 0; j &lt; rows; j++)
  {
      for (int i = 0; i &lt; aSet.Count; i++)
      {
          Console.Write(array[i, j] + " / ");
      }
      Console.WriteLine();
  }
  //end
  
  Console.ReadLine();
  </code></pre>
  
  <p>However, the code does not output the correct string array (though it is close). What I would like it to out put is the following:</p>
  
  <p>low / slow / light /</p>
  
  <p>low / slow / medium /</p>
  
  <p>low / slow / heavy /</p>
  
  <p>low / Fast / light /</p>
  
  <p>low / Fast / medium /</p>
  
  <p>low / Fast / heavy /</p>
  
  <p>medium / slow / light /</p>
  
  <p>medium / slow / medium /</p>
  
  <p>medium / slow / heavy /</p>
  
  <p>medium / Fast / light /</p>
  
  <p>medium / Fast / medium /</p>
  
  <p>medium / Fast / heavy /</p>
  
  <p>high / slow / light /</p>
  
  <p>high / slow / medium /</p>
  
  <p>high / slow / heavy /</p>
  
  <p>high / Fast / light /</p>
  
  <p>high / Fast / medium /</p>
  
  <p>high / Fast / heavy /</p>
  
  <p>Now the variables in this problem is the number of customSets in the list and the number of elements in each CustomSet.  </p>