473,761 Members | 8,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5767
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.Dat aTable does not implement either of these Interfaces. It
does, however have a Rows property, which is a System.Data.Dat aRowCollection
of System.Data.Dat aRow instances. System.Data.Dat aRowCollection does not
implement IEnumerable directly, but inherits
System.Data.Int ernalDataCollec tionBase, 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, DataRowCollecti on, and InternalDataCol lectionBase:

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

May 10 '07 #3
Thanks guys.

"Kevin Spencer" <un**********@n othinks.comwrot e in message
news:ua******** ******@TK2MSFTN GP02.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.Dat aTable does not implement either of these Interfaces. It
does, however have a Rows property, which is a
System.Data.Dat aRowCollection of System.Data.Dat aRow instances.
System.Data.Dat aRowCollection does not implement IEnumerable directly, but
inherits System.Data.Int ernalDataCollec tionBase, 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, DataRowCollecti on, and InternalDataCol lectionBase:

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

May 11 '07 #4

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

Similar topics

9
1844
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 state field in the collection, and every time something is inserted or deleted from the collection, I will just change the guid. Enumerator will just have to compare the guid received in the begging to the current one. If they are different, the...
1
2126
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 'Length' why is that? is this approach right? I want to develop an OO App. so is this approach right?
3
7123
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 bool IEnumerator.MoveNext() an void IEnumerator.Reset() The help to IEnumerator.MoveNext describes that "after the end of the collection is passed, subsequent calls to MoverNect return false until reset is called" When, however, I have two...
3
4329
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
3702
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 property "Current". The challange is that I need to implement two versions of the property: one of type System::Object as required by Collections::IEnumerator, the other of type T^ as required by Collections::Generic::IEnumerator<T> ...
11
2218
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 via the GetEnumerator method would be synchronized with the collction; if the collection changes, the existing enumerators are notified via an event. The accompanying EventArgs derived class object carries information about the change to the...
3
3597
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 IEnumerator<stringGetEnumerator() {
5
9375
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 interface. Please help me resolve the error I was able to implement the non Generics version
2
11783
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> implements IDisposable, but not IEnumerator. Anyone? Thanks, HC
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.