多维数组枚举器是否保证所有实现的顺序相同?
Does multidimensional array enumerator guarantee the same order for all implementations?
这是否会始终在所有平台上以相同顺序打印元素?
foreach (var el in multidimArray) Console.WriteLine(el);
我正在寻找规范或任何官方的报价。
是的,内置数组的枚举顺序定义明确且与平台无关。
参见C# Specification的相关部分(8.8.4 foreach语句):
The order in which foreach traverses the elements of an array, is as follows:
- For single-dimensional arrays elements are traversed in increasing index order, starting with index 0 and ending with index Length – 1.
- For multi-dimensional arrays, elements are traversed such that the indices of the rightmost dimension are increased first, then the next left dimension, and so on to the left.
这是否会始终在所有平台上以相同顺序打印元素?
foreach (var el in multidimArray) Console.WriteLine(el);
我正在寻找规范或任何官方的报价。
是的,内置数组的枚举顺序定义明确且与平台无关。
参见C# Specification的相关部分(8.8.4 foreach语句):
The order in which foreach traverses the elements of an array, is as follows:
- For single-dimensional arrays elements are traversed in increasing index order, starting with index 0 and ending with index Length – 1.
- For multi-dimensional arrays, elements are traversed such that the indices of the rightmost dimension are increased first, then the next left dimension, and so on to the left.