473,800 Members | 2,418 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 1810
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
4379
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
2736
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
9378
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
4587
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 releationship, just like IList<Tand IList. I googled the web and found two related articles....
0
1247
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
1783
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 non-Count- friendly implementation to work happily.
2
6172
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
8875
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
4968
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
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10253
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.