473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

IEnumerable Item Count

Is at all possible to get IEnumerable Item Count without having to loop
through using GetEnumerator() ??
Thanks
Jan 27 '06 #1
3 19732
> Is at all possible to get IEnumerable Item Count without having to
loop
through using GetEnumerator() ??
Thanks


<see langword="true" /> if the object implementing IEnumberable has a Count
property; otherwise <see langword="false" />.

Wow. That's even geeky for me.. ;)
Jan 27 '06 #2
Oliver Gargour <ne********@garwin.be> wrote:
Is at all possible to get IEnumerable Item Count without having to loop
through using GetEnumerator() ??


Not in general. There may not even be a sensible meaning to that. For
instance, it would be possible (potentially useful even) to write an
IEnumerable implementation on top of TextReader, so you could do:

foreach (string line in new LineReader(myTextReader))
{
}

Now, potentially that TextReader is coming over a network connection
which may keep giving text forever.

Alternatively, a random number generator could implement IEnumerable -
again, no sensible concept of count.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 27 '06 #3

"chris martin" <chris_m|NOSPAM|@caliber|SPAM|web.com> wrote in message
news:44**************************@news.easynews.co m...
Is at all possible to get IEnumerable Item Count without having to
loop
through using GetEnumerator() ??
Thanks


<see langword="true" /> if the object implementing IEnumberable has a
Count property; otherwise <see langword="false" />.

Wow. That's even geeky for me.. ;)


Check to see whether the object implements ICollection (which has a Count
property).

If a class is IEnumerable and has a Count then I can't think of a good
reason why it would not implement ICollection since ICollection =
IEnumerable + Count + a few methods that MUST be implementable.

Better yet overload your method with one taking ICollection
Jan 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the...
4
by: Pete | last post by:
Okay, I'm still stuck with this problem. Here's a quick recap/summary :- 1. Page 1:User checks 3 out of 10 checkboxes and submits form to page 2 2. Page 2:Item count shows 3 items. User checks...
3
by: phil | last post by:
Using Tkinter Canvas to teach High School Geometry with A LOT of success. My drawing gets very slow after a lot of actions. For instance I have created code to rotate a set of objects about a...
2
by: Ash Jones | last post by:
I trying to do nested items in a collection. I've got an item which one of the properties is subitems, which is a collection of item. can do the root level but if i do a subitem at design time i...
1
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the...
1
by: Alex | last post by:
I'm working with a repeater control that contains dynamically created custom composite controls. Within the ITemplate.InstantiateIn() method I need access to the repeater's datasource's item count....
3
by: mkiger | last post by:
Hey Guys. I'm making an asp.net app and I have a question regarding listboxes. I have a list box and I would like some of the items to be bold based on certian criteria. Is this possible? matt
5
by: Tin Gherdanarra | last post by:
Dear mpdls, here is a simple example of an IEnumerable that generates integers: It works, but I have only a vague idea of what's going on. I understand that /yield/ wraps the humble integer...
2
by: AZKing | last post by:
Hi, I am creating a query where I would like to count the number of specific items in a certain column of another query. I can do this for one item, for example: SELECT DISTINCTROW., Count(.)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.