Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Question about Collection generic class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roy - 18 Jul 2007 15:22 GMT
Here is the definition for System.Collection.ObjectModel.Collection generic
class:
[SerializableAttribute]
[ComVisibleAttribute(false)]
public class Collection<T> : IList<T>, ICollection<T>,
    IEnumerable<T>, IList, ICollection, IEnumerable
The class does not support IEnumerator or IEnumerator<T> interfaces. How
come I can still use "foreach" against the class? I think a class has to
support IEnumerable and IEnumerator for "foreach". Anyone can tell me the
reason? I need to implement a class similar to it (can not derive from it in
my case).
Alex Meleta - 18 Jul 2007 15:42 GMT
Hi Roy,

Because ICollection already has IEnumerable, needed for a foreach loop to
access the enumerator. IList based on ICollection. So here is more then enough
enumerators.

Regards, Alex
[TechBlog] http://devkids.blogspot.co
Roy - 18 Jul 2007 16:52 GMT
Is IEnumerator needed for "foreach"?

> Hi Roy,
>
[quoted text clipped - 4 lines]
> Regards, Alex
> [TechBlog] http://devkids.blogspot.com
Alex Meleta - 18 Jul 2007 19:27 GMT
Hi Roy,

Yes, but foreach uses IEnumerable to obtain IEnumerator (IEnumerable.GetEnumerator()).
Without IEnumerable only while (or such) can be used to "manualy" iterating
the collection, not the foreach statement.

Regards, Alex
[TechBlog] http://devkids.blogspot.com

R> Is IEnumerator needed for "foreach"?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.