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

linq - if I select nodes from an XDocument is the order always preserved?

问题描述:

Let's say I have nodes like so:

<Params>

<Param val="C" />

<Param val="D" />

<Param val="A" />

<Param val="B" />

<Params>

If I select the Descendants of Params is the order always preserved? I want C to always be first when I iterate through the ordered list that I'll be dropping these into. Or do I need to come up with a different solution for ordering nodes? I'd like to stay away from numbers (order="1", 2 etc.) so any suggestions would be great.

网友答案:

The documentation for the Descendants property says:

Returns a collection of the descendant elements for this document or element, in document order.

So the answer is yes, they will be returned in the same order they appear in the original XML.

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