473,574 Members | 18,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<Tbu t 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 1796
GiJeet <gi****@yahoo.c omwrote:
Hello, I know that all that=3Fs required to use linq to objects, is the
collection must implement IEnumerable<Tbu t 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.co m>
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<Tth at 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.c omwrote:
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...objec ts? collections?
both?

G


Jun 27 '08 #4
GiJeet <gi****@yahoo.c omwrote:
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<Tth at 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.co m>
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.c omwrote:
On Apr 26, 5:47 pm, GiJeet <gij...@yahoo.c omwrote:
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...objec ts? 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<Tfr om an IEnumerable.)

--
Jon Skeet - <sk***@pobox.co m>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4367
by: Doug Dew | last post by:
This won't compile: using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>; namespace MyNamespace { public class MyClass<T> : IEnumerable<T> { // Appropriate stuff here }
15
2718
by: Gustaf | last post by:
Using VS 2005. I got an 'IpForm' class and an 'IpFormCollection' class, containing IpForm objects. To iterate through IpFrom objects with foreach, the class is implemented as such: public class IpFormCollection : IEnumerable<IpForm> { ArrayList forms = new ArrayList(); public IEnumerator<IpFormGetEnumerator() {
5
9369
by: Shikari Shambu | last post by:
Hi, I am trying to implement a collection that implements IEnumerable<T>. I keep getting the following error 'IEnumerator<...>.Current' in explicit interface declaration is not a member of interface. Please help me resolve the error I was able to implement the non Generics version
2
4580
by: Morgan Cheng | last post by:
In .Net 2.0, Generics are introduced. I found that IEnumerable<T> inherites from IEnumerable. This makes implementation of IEnumerable<Thas to have two GetEnumerator methods defined( one for IEnumerable<Tand the other for IEnumerable). I doubt why .Net class hierarchy is designed in such a way. IMHO, they should not have inheritance...
0
1238
by: Andrus | last post by:
I noticed that Linq-SQL DataContext ExecuteQuery method does not have new() constraint: IEnumerable<TResultExecuteQuery( command, ... ) IEnumerable must return object so it must create this object in some way. Any idea why and how ExecuteQuery<Tcan be implemented witout new() constraint ?
0
1771
by: Marc Gravell | last post by:
You could bypass the List<T>'s tendency to use ICollection<Tby simply not giving it an ICollection<T- for example, with the C# 3 extension method below you could use: List<Tlist = new List<T>(source.AsEnumerableOnly()); The AsEnumerableOnly() *only* exposes IEnumerable<T(OK, it also exposes IEnumerable and IDisposable ;-p), allowing your...
2
6127
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists, like List<char>. What I have working is : Type type = newObj.GetType(); //newObj is what I'm trying to dump
1
8865
by: shapper | last post by:
Hello, On my MVC projects I often create classes which contains properties which are lists of other classes. Should I start using IQueryable<Tor IEnumerable<Tinstead of List<T>? What are the differences and when should I use IQueryable<T>, IEnumerable<Tor List<T>?
2
4950
by: Berryl Hesh | last post by:
Converting in the other direction , IEnumerable<Interfaceto List<ImplInterface>, I can just create a new List<ImplInterface(data) where data is IEnumerable<Interface>. How can I convert the List<ImplInterfaceto IEnumerable<Interface>? Thanks, BH
0
8258
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6486
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5325
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3759
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2255
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.