|
|
|
date: Tue, 22 Jul 2008 23:31:43 +0200,
group: microsoft.public.dotnet.languages.csharp
back
Re: Getting information from IEnumerable
On Jul 23, 1:31 am, "K Viltersten" wrote:
> At this point, i usually use a foreach-loop
> to run through all the XElement's in my
> IEnumerable<XElement>. I noticed, i'd like
> to address the elements using brackets and
> an index (or like a dictionary, with the
> tag name as a key).
>
> Is it easily doable? If so, how?
If you just need to get an element at a specific index once, use
ElementAt() method (but you should be aware that it does a linear scan
unless the object it's called is actually an IList<T> - then it uses
the indexer). To find an element by name, use Elements() method which
takes an XName argument; if there is precisely one such element, use
First() method to get the first value from the IEnumerable returned by
Elements().
date: Wed, 23 Jul 2008 00:03:00 -0700 (PDT)
author: Pavel Minaev
|
|