469,903 Members | 1,461 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

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 5563
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by juan | last post: by
3 posts views Thread by Hans | last post: by
3 posts views Thread by starter | last post: by
1 post views Thread by midnight madness | last post: by
11 posts views Thread by Leslie Sanford | last post: by
3 posts views Thread by rossum | last post: by
5 posts views Thread by Shikari Shambu | last post: by
2 posts views Thread by Henri.Chinasque | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.