Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 473
Nick Avatar asked Jul 12 '11 10:07

Nick


2 Answers

Try e.ElementsBeforeSelf().Count()

like image 118
dahlbyk Avatar answered Sep 18 '22 02:09

dahlbyk


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

var index = document.Elements().ToList().IndexOf(element);
like image 23
CamronBute Avatar answered Sep 21 '22 02:09

CamronBute