Nick
Nick

Reputation: 25828

Index of Child XElement

Given an XElement is there a way to find out that element's index within the parent container?

I know there must be but I just can't figure it out!

Thanks!

Upvotes: 7

Views: 5476

Answers (3)

chad
chad

Reputation: 1

In VB

Dim Index As String = i.ToString.IndexOf(i.ToString)

Upvotes: -1

Camron B
Camron B

Reputation: 1840

Try using .ToList().IndexOf() which returns the index of the object you pass in. Example:

var index = document.Elements().ToList().IndexOf(element);

Upvotes: 1

dahlbyk
dahlbyk

Reputation: 77620

Try e.ElementsBeforeSelf().Count()

Upvotes: 13

Related Questions