Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Tue, 22 Jul 2008 23:31:43 +0200,    group: microsoft.public.dotnet.languages.csharp        back       


Getting information from IEnumerable   
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?

--
Regards
Konrad Viltersten
date: Tue, 22 Jul 2008 23:31:43 +0200   author:   K Viltersten

Re: Getting information from IEnumerable   
On Tue, 22 Jul 2008 14:31:43 -0700, 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?

When you write "my IEnumerable<XElement>" does that mean that you're the  
author of the class that returns the IEnumerable?

If so, yes...you should easily be able to add an indexer.  See:
http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
date: Tue, 22 Jul 2008 14:35:20 -0700   author:   Peter Duniho

Re: Getting information from IEnumerable   
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?

Yes. Just stuff it in a List<XElement>. There
is a List<> constructor that takes an IEnumerable<>
as argument.

And if it comes from LINQ for XML there is also
ToList in that.

Arne
date: Tue, 22 Jul 2008 17:38:58 -0400   author:   Arne Vajhøj

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

Re: Getting information from IEnumerable   
>> 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?
>
> Yes. Just stuff it in a List<XElement>. There
> is a List<> constructor that takes an IEnumerable<>
> as argument.
>
> And if it comes from LINQ for XML there is also
> ToList in that.

Great info! Thanks to all!

-- 
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
date: Wed, 23 Jul 2008 14:13:08 +0200   author:   K Viltersten

Re: Getting information from IEnumerable   
>> 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?
>
> Yes. Just stuff it in a List<XElement>. There
> is a List<> constructor that takes an IEnumerable<>
> as argument.
>
> And if it comes from LINQ for XML there is also
> ToList in that.

As far i can see, DotNet complains when i try to
shove the obtained IEnumerable<XElement> into a
List<XElement>... Are you sure it's possible with
no explicit casting involved?

-- 
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
date: Wed, 23 Jul 2008 18:53:43 +0200   author:   K Viltersten

Re: Getting information from IEnumerable   
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?
>>
>> Yes. Just stuff it in a List<XElement>. There
>> is a List<> constructor that takes an IEnumerable<>
>> as argument.
>>
>> And if it comes from LINQ for XML there is also
>> ToList in that.
>
> As far i can see, DotNet complains when i try to
> shove the obtained IEnumerable<XElement> into a
> List<XElement>... Are you sure it's possible with
> no explicit casting involved?

No casting.

But you do need to call the List<T> constructor that accepts an 
IEnumerable<T>.

e.g.


List<T> theList = new List(theEnumerable);

and not

List<T> theList = theEnumerable;
date: Wed, 23 Jul 2008 13:14:03 -0500   author:   Ben Voigt [C++ MVP] am

Re: Getting information from IEnumerable   
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?
>> Yes. Just stuff it in a List<XElement>. There
>> is a List<> constructor that takes an IEnumerable<>
>> as argument.
>>
>> And if it comes from LINQ for XML there is also
>> ToList in that.
> 
> As far i can see, DotNet complains when i try to
> shove the obtained IEnumerable<XElement> into a
> List<XElement>... Are you sure it's possible with
> no explicit casting involved?

"stuff it in" = use it as argument for constructor

assignment does not really stuff much

Arne
date: Wed, 23 Jul 2008 20:46:45 -0400   author:   Arne Vajhøj

Re: Getting information from IEnumerable   
On Jul 23, 10:14 pm, "Ben Voigt [C MVP]" <r...@nospam.nospam> wrote:
> > As far i can see, DotNet complains when i try to
> > shove the obtained IEnumerable<XElement> into a
> > List<XElement>... Are you sure it's possible with
> > no explicit casting involved?
>
> No casting.
>
> But you do need to call the List<T> constructor that accepts an
> IEnumerable<T>.
>
> e.g.
>
> List<T> theList = new List(theEnumerable);

Or, a tiny bit shorter with LINQ:

var theList = theEnumerable.ToList();
date: Wed, 23 Jul 2008 23:54:34 -0700 (PDT)   author:   Pavel Minaev

Re: Getting information from IEnumerable   
>>> Yes. Just stuff it in a List<XElement>. There
>>> is a List<> constructor that takes an IEnumerable<>
>>> as argument.
>>>
>>> And if it comes from LINQ for XML there is also
>>> ToList in that.
>>
>> As far i can see, DotNet complains when i try to
>> shove the obtained IEnumerable<XElement> into a
>> List<XElement>... Are you sure it's possible with
>> no explicit casting involved?
>
> "stuff it in" = use it as argument for constructor
> assignment does not really stuff much

I see you, very correctly and clearly so,
mention the use of constructor, when talking
about stuffing in. I must have missed it.
Please accept my appology.

I though by stuffing in you ment:
  int stuffee = 3;
  double stuffer = stuffee;
Well, i'll be off correcting the error.
Thanks to all of you guys!

-- 
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
date: Thu, 24 Jul 2008 12:47:11 +0200   author:   K Viltersten

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us