IEnumerator

M

Marc Gravell

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
 
K

Kevin Spencer

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/library/system.collections.ienumerator.aspx
http://msdn2.microsoft.com/en-us/li...system.data.datarowcollection.aspx--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" <[email protected]> wrote in messageHi.>> I have read some examples of IEnumerator athttp://www.codeproject.com/csharp/csenumerators.asp> What 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.>
 
E

EmilH

Thanks guys.

Kevin Spencer said:
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/library/system.collections.ienumerator.aspx
http://msdn2.microsoft.com/en-us/li...system.data.datarowcollection.aspx--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" <[email protected]>
wrote in messageHi.>> I
have read some examples of IEnumerator
athttp://www.codeproject.com/csharp/csenumerators.asp> What 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.>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top