C# - Most efficient way to iterate through multiple arrays/list
<p>I have five arrays of varying lengths and I need to iterate through all of them generating all possible combinations of the contents.  I'm currently using 5 nested for loops like so:</p>

<pre><code>for (int a = 1; a &lt; Array1.Length - 1; a++)
  {
    for (int b = 1; b &lt; Array2.Length - 1; b++)
      {
        for (int c = 1; c &lt; Array3.Length - 1; c++)
          {
            for (int d = 1; d &lt; Array4.Length - 1; d++)
              {
                for (int e = 1; e &lt; Array5.Length - 1; e++)
                  {
                    //do something
                  }
              }
          }
      }
  }
</code></pre>

<p>Due to the size of the arrays, I end up with more than 456 million iterations.  I'm pretty new to programming in general, and C# specifically.  I'm just curious if there is a more efficient way to accomplish this.</p>

<p>Thank you.</p>
