开发者

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<>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜