<p>Let's say I have a .NET Array of n number of dimensions.  I would like to foreach through the elements and print out something like:</p>

<pre><code>[0, 0, 0] = 2
[0, 0, 1] = 32
</code></pre>

<p>And so on.  I could write a loop using some the Rank and dimension functions to come up with the indices.  Is there a built in function instead?</p>

[{'answer_id': 26546, 'author': 'Gabriël', 'author_id': 2104, 'author_profile': 'https://Stackoverflow.com/users/2104', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://forums.msdn.microsoft.com/en-US/csharplanguage/thread/2ca85aa4-0672-40ad-b780-e181b28fcd80/" rel="nofollow noreferrer">Take a look at this:</a> might helpful for you.</p>\n'}, {'answer_id': 26582, 'author': 'Jake Pearson', 'author_id': 632, 'author_profile': 'https://Stackoverflow.com/users/632', 'pm_score': 3, 'selected': True, 'text': '<p>Thanks for the answer, here is what I wrote while I waited:</p>\n\n<pre><code>public static string Format(Array array)\n{\n    var builder = new StringBuilder();\n    builder.AppendLine("Count: " + array.Length);\n    var counter = 0;\n\n    var dimensions = new List&lt;int&gt;();\n    for (int i = 0; i &lt; array.Rank; i++)\n    {\n        dimensions.Add(array.GetUpperBound(i) + 1);\n    }\n\n    foreach (var current in array)\n    {\n        var index = "";\n        var remainder = counter;\n        foreach (var bound in dimensions)\n        {\n            index = remainder % bound + ", " + index;\n            remainder = remainder / bound;\n        }\n        index = index.Substring(0, index.Length - 2);\n\n        builder.AppendLine("   [" + index + "] " + current);\n        counter++;\n    }\n    return builder.ToString();\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26522', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/632/']