471,337 Members | 882 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Linq, and how to determine if IEnumerable<T>

Hello, I know that all thatís required to use linq to objects, is the
collection must implement IEnumerable<Tbut how to know if a
collection implements this interface? For example one of the books
Iím reading uses the running system processes and I wouldn't know off
the top of my head if these processes implement the IEnumerable<T>
interface so is there a quick way to know if some objects implement
this interface without writing code to test it?

thx
G
Jun 27 '08 #1
5 1713
GiJeet <gi****@yahoo.comwrote:
Hello, I know that all that=3Fs required to use linq to objects, is the
collection must implement IEnumerable<Tbut how to know if a
collection implements this interface? For example one of the books
I=3Fm reading uses the running system processes and I wouldn't know off
the top of my head if these processes implement the IEnumerable<T>
interface so is there a quick way to know if some objects implement
this interface without writing code to test it?
Pretty much every collection implements at least IEnumerable. For any
particular collection though, just check the documentation.

I wouldn't expect a single process to implement IEnumerable<T>, but the
*collection* of running processes almost certainly will.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jun 27 '08 #2
but the *collection* of running processes almost certainly will.

So, just to make sure I have this correct, itís always the collection
we create to hold our objects, whether we create a List<Tor Array or
Collection<Tor even IEnumerable<Tthat needs to implement this
interface and it doesnít matter what objects we insert into the
collect (system processes, strings, ints, cars, etc), because itís the
collect we enumerate over. Do I have this right?

G
Jun 27 '08 #3
On Apr 26, 5:47 pm, GiJeet <gij...@yahoo.comwrote:
but the *collection* of running processes almost certainly will.
Are we always querying against a collection (in Linq-to-objects)? I
hear the term "queryable types", is this referring to just collections
or ANY object that implements IEnumerable? So, I guess I'm still not
clear on exactly what we can query against...objects? collections?
both?

G


Jun 27 '08 #4
GiJeet <gi****@yahoo.comwrote:
but the *collection* of running processes almost certainly will.

So, just to make sure I have this correct, it=3Fs always the collection
we create to hold our objects, whether we create a List<Tor Array or
Collection<Tor even IEnumerable<Tthat needs to implement this
interface and it doesn=3Ft matter what objects we insert into the
collect (system processes, strings, ints, cars, etc), because it=3Fs the
collect we enumerate over. Do I have this right?
Yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jun 27 '08 #5
GiJeet <gi****@yahoo.comwrote:
On Apr 26, 5:47 pm, GiJeet <gij...@yahoo.comwrote:
but the *collection* of running processes almost certainly will.

Are we always querying against a collection (in Linq-to-objects)?
Well, querying against "something that implements IEnumerable".
(Usually IEnumerable<Tas well.) It doesn't need to be an in-memory
collection, for example.
I hear the term "queryable types", is this referring to just collections
or ANY object that implements IEnumerable? So, I guess I'm still not
clear on exactly what we can query against...objects? collections?
both?
Anything that implements IEnumerable/IEnumerable<T>. (Most of LINQ to
Objects requires IEnumerable<T>, but you can use Cast/OfType to obtain
an IEnumerable<Tfrom an IEnumerable.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Gustaf | last post: by
5 posts views Thread by Shikari Shambu | last post: by
2 posts views Thread by Morgan Cheng | last post: by
2 posts views Thread by Fred Mellender | last post: by
1 post views Thread by shapper | last post: by
2 posts views Thread by Berryl Hesh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.