加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 多维数组枚举器是否保证所有实现的顺序相同?

发布时间:2020-12-15 23:31:29 所属栏目:百科 来源:网络整理
导读:这总是会在所有平台上以相同的顺序打印元素吗? foreach (var el in multidimArray) Console.WriteLine(el); 我正在寻找规格或任何官方报价. 解决方法 是的,内置数组的枚举顺序是明确定义的,与平台无关. 参见C# Specification的相关部分(8.8.4 foreach声明)
这总是会在所有平台上以相同的顺序打印元素吗?

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读