Implement the IEnumerator interface in VB. NET

Source: Internet
Author: User
Tags dot net

Implement the IEnumerator interface in VB. NET
This object similar to parent-child relationship is often used in object-oriented design. For example, in my current project, there are order objects, I want to use the Iterator mode to encapsulate products under an order. The IEnumerator interface in dot Net is used for iteration, to support the for each operation in dot Net.
To implement the IEnumerator interface, you must implement the following functions to support operations on the IEnumerator interface:
Overridable ReadOnly Property Current () As Object
Current is used to obtain the Current object during iteration.
Public Overridable Function MoveNext () As Boolean
MoveNext is used to point the iteration pointer to the next object in the iteration process. Initially, the iteration Pointer Points to the beginning of the Set (before the first node). Once the collection ends, before calling Reset, false is returned for subsequent calls to MoveNext.
Overridable Sub Reset ()
Set the enumeration number to its initial position before the first element in the set.
As long as the Set remains unchanged, the enumerated number remains valid. If a set is modified (for example, adding, modifying, or deleting an element), the enumerated number is invalid and cannot be restored. The next call to MoveNext or Reset will cause InvalidOperationException.
The following is a specific image for implementing the IEnumerator interface.
'------------------------ Class implementing the IEnumerator interface ----------------------------------
Imports System. Collections
'The actual implementation here is the System. Collections. IEnumerable interface. IteratorProduct uses this interface to provide users with operations on the IEnumerator interface.
Public Class IteratorProduct: Implements System. Collections. IEnumerable
Private Products As Collection all Products whose collections are stored in the order
Private item As Integer =-1
Public Sub New ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.