当前位置: 动力学知识库 > 问答 > 编程问答 >

Order of a newly defined C# array

问题描述:

In C# 3.0, when I pass an array of strings to a method in the manner below, will the order I define them in be retained or are there conditions under which the order can change? Is this documented somewhere that I haven't seen?

CalculateOmniturePageName(new[] { Model.GetOmnitureDomain(), Model.SectionTitle, Model.Title })

网友答案:

The order is fixed. The first item is index 0, the next is index 1, and so on. It's defined in the spec, see section 12.6.

The expressions initialize array elements in increasing order, starting with the element at index zero.

The entire (annotated) spec is available in dead-tree form and is a surprising easy and enlightening read.

网友答案:

An Array like you are using is always ordered in the order you put them in. This is contrasted with a hash table, or a set, or a dictionary, which will be in no particular order. There are other 'unordered' collection types, but this is good enough to illustrate my point. On the other hand, if you want to use another container which will retain the order you put them in, you can also use a List<>

分享给朋友:
您可能感兴趣的文章:
随机阅读: