473,320 Members | 1,724 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.

IEnumerator

Hi.

I have read some examples of IEnumerator at
http://www.codeproject.com/csharp/csenumerators.asp
What if I have 2 arrays or collections, for example a DataSet which has 2
DataTables in my class which derives from IEnumerator? How to implement
Current property to return current item of the desired DataTable?

Thanks.
Emil.
May 10 '07 #1
3 5740
What exactly are you trying to do...? Are you trying to provide an
iterator that unions the two tables? If so, in 1.1 perhaps (over
successive MoveNext() calls) get an iterator from the first table,
exhaust it, get an iterator from the second table, exhaust that...
each time Current simply forwards to the slave iterator's Current
(I'll try to knock a quick example together).

In 2.0 yield might offer a simpler solution.

However, from your description I wasn't sure if you are talking about
something closer to "currency"? So again - what are you trying to do?

Marc
May 10 '07 #2
I don't believe you've understood what you were reading. First, IEnumerator
is an interface, which means that classes cannot derive from it (inherit
it), but implement it. Interfaces are "contracts" that specify what
properties and methods any class which implements that Interface must have.
A class can only inherit from one class, but it may implement many
Interfaces.

IEnumerator is an interface for creating classes that are used by other
classes to iterate through an aggregation of multiple instances of some
class. It contains definitions of one property (Current) and 2 methods
(MoveNext and Reset), which are used to move through an aggregation of class
instances.

I think you may be confusing IEnumerator and IEnumerable, which is another
Interface containing a single method (GetEnumerator), which returns an
instance of a class that implements the IEnumerator interface. Many
aggregate types, including Arrays and Collections of various types,
implement IEnumerator, to provide common mechanisms for navigation through
these aggregations.

System.Data.DataTable does not implement either of these Interfaces. It
does, however have a Rows property, which is a System.Data.DataRowCollection
of System.Data.DataRow instances. System.Data.DataRowCollection does not
implement IEnumerable directly, but inherits
System.Data.InternalDataCollectionBase, which implements IEnumerable (not
IEnumerator). Therefore, you CAN use the IEnumerable Interface in the Rows
property of a DataTable, to iterate through the Rows.

That' about as close as I can come to answering your question, as, put into
context, it doesn't really make much sense. That is, I am not sure what
you're asking, because you prefaced your question with erroneous
assumptions, and therefore I can't make out what exactly you want to do.

I can, however, give you a few references on IEnumerator, IEnumerable,
DataTable, DataRowCollection, and InternalDataCollectionBase:

http://msdn2.microsoft.com/en-us/lib...numerator.aspx
http://msdn2.microsoft.com/en-us/lib...spx--HTH,Kevin SpencerMicrosoft MVPPrinting Components, Email Components,FTP Client Classes, Enhanced Data Controls, much more.DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net"EmilH" <em*****@yahoo.comwrote in messagenews:%2***************@TK2MSFTNGP05.phx.gbl ...Hi.>I have read some examples of IEnumerator athttp://www.codeproject.com/csharp/csenumerators.aspWhat if I have 2 arrays or collections, for example a DataSet which has 2DataTables in my class which derives from IEnumerator? How to implementCurrent property to return current item of the desired DataTable?>Thanks.Emil.>

May 10 '07 #3
Thanks guys.

"Kevin Spencer" <un**********@nothinks.comwrote in message
news:ua**************@TK2MSFTNGP02.phx.gbl...
>I don't believe you've understood what you were reading. First, IEnumerator
is an interface, which means that classes cannot derive from it (inherit
it), but implement it. Interfaces are "contracts" that specify what
properties and methods any class which implements that Interface must have.
A class can only inherit from one class, but it may implement many
Interfaces.

IEnumerator is an interface for creating classes that are used by other
classes to iterate through an aggregation of multiple instances of some
class. It contains definitions of one property (Current) and 2 methods
(MoveNext and Reset), which are used to move through an aggregation of
class instances.

I think you may be confusing IEnumerator and IEnumerable, which is another
Interface containing a single method (GetEnumerator), which returns an
instance of a class that implements the IEnumerator interface. Many
aggregate types, including Arrays and Collections of various types,
implement IEnumerator, to provide common mechanisms for navigation through
these aggregations.

System.Data.DataTable does not implement either of these Interfaces. It
does, however have a Rows property, which is a
System.Data.DataRowCollection of System.Data.DataRow instances.
System.Data.DataRowCollection does not implement IEnumerable directly, but
inherits System.Data.InternalDataCollectionBase, which implements
IEnumerable (not IEnumerator). Therefore, you CAN use the IEnumerable
Interface in the Rows property of a DataTable, to iterate through the
Rows.

That' about as close as I can come to answering your question, as, put
into context, it doesn't really make much sense. That is, I am not sure
what you're asking, because you prefaced your question with erroneous
assumptions, and therefore I can't make out what exactly you want to do.

I can, however, give you a few references on IEnumerator, IEnumerable,
DataTable, DataRowCollection, and InternalDataCollectionBase:

http://msdn2.microsoft.com/en-us/lib...numerator.aspx
http://msdn2.microsoft.com/en-us/lib...spx--HTH,Kevin
SpencerMicrosoft MVPPrinting Components, Email Components,FTP Client
Classes, Enhanced Data Controls, much more.DSI PrintManager, Miradyne
Component Libraries:http://www.miradyne.net"EmilH" <em*****@yahoo.com>
wrote in messagenews:%2***************@TK2MSFTNGP05.phx.gbl ...Hi.>I
have read some examples of IEnumerator
athttp://www.codeproject.com/csharp/csenumerators.aspWhat if I have 2
arrays or collections, for example a DataSet which has 2DataTables in my
class which derives from IEnumerator? How to implementCurrent property to
return current item of the desired DataTable?>Thanks.Emil.>

May 11 '07 #4

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

Similar topics

9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
1
by: juan | last post by:
hi i have a teachers class where i want the user to enter a few teachers and iterate thru them. In the main i get an error System.Collections.IEnumerator' does not contain a definition for...
3
by: Hans | last post by:
I implemented the IEnumerator interface in some classes to enable the use of the foreach statement. As you probalbly know, the interface asks for the implementation of object IEnumerator.Curren...
3
by: starter | last post by:
I am trying to learn IEnumerator and collections(ArrayList, Hashtable) in .NET. Can anyone tell me what is IEnumerator used for and any online resources would be helpful. Thanks
1
by: midnight madness | last post by:
I tried but failed to implement a template class that support IEnumerator<T> interface using C++/CLI in VS 2005 Professional version. I could not figure out the proper syntax to implement the...
11
by: Leslie Sanford | last post by:
I've been kicking around an idea mostly as a thought experiment at this point. The idea is to create a thread safe collection that implements the IEnumerable interface. The enumerators it creates...
3
by: rossum | last post by:
I have been trying to get the IEnumerable interface to compile, and am having some difficulties. When I try to compile: class TestIEnum : IEnumerable<string{ string theStrings; public...
5
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...
2
by: Henri.Chinasque | last post by:
I have a feeling this is a dumb one, but here it is: IEnumerator<Timplements IDisposable, but the thing is I'm not sure what I'm supposed to dispose! I'm also curious why IEnumerator<T>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.