title: Multidimensional arrays do not implement IEnumerable<T>, or do they?
body: <p>For the reasons that I still do not understand (<a href="https://stackoverflow.com/questions/275073/why-does-c-multidimensional-arrays-not-implement-ienumerablet">see this SO question</a>) multidimensional arrays in CLR do not implement <code>IEnumerable&lt;T&gt;</code>. So the following does not compile:</p>
  
  <pre><code>var m = new int[2,2] {{1, 2}, {3, 4}};
  var q = from e in m select e;
  </code></pre>
  
  <p>Then how come that this <strong>works just fine in VB.NET</strong>?</p>
  
  <pre><code>Sub Main()
      Dim m(,) As Integer = {{1, 2}, {3, 4}}
      Dim q = From e In m Select e
  
      For Each i In q
          Console.WriteLine(i)
      Next
  End Sub
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>The following code works because the C# compiler replaces the <code>foreach</code> with <code>for</code> loops to go through each dimension.</p>
  
  <pre><code>foreach(var e in m)
      Console.WriteLine(e);
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>int[,] numArray3 = new int[,] { { 2, 2 }, { 3, 3 } };
  int upperBound = numArray3.GetUpperBound(0);
  int num4 = numArray3.GetUpperBound(1);
  for (int i = numArray3.GetLowerBound(0); i &lt;= upperBound; i++)
  {
      for (int j = numArray3.GetLowerBound(1); j &lt;= num4; j++)
      {
          int num = numArray3[i, j];
          Console.WriteLine(num);
      }
  }
  </code></pre>