문제

I have one XElement object where in there are Nodes present inside that object, i want to get the Nodes count without iterating over all the elements using IEnumarable.

How do i do this?

Note: This answer here is not applicable in my case because no support for.Count in SilverLight

도움이 되었습니까?

해결책

Count is an extension method of Enumerable class. To be able to use it, you should add

using System.Linq;

to your code.

다른 팁

Infact using linq you can count the number of nodes like this,

 doc = System.Xml.Linq.XDocument.Load("YourXml");
 doc.Root.Descendants().Count(d => (string)d.Attribute("attName") == "value");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top