在面向對象的設計中
要實現IEnumerator接口
Overridable ReadOnly Property Current() As Object
Current用於在迭代過程中得到當前的對象
Public Overridable Function MoveNext() As Boolean
MoveNext用於在迭代過程中將迭代指針指向下一個對象
Overridable Sub Reset()
將枚舉數設置為其初始位置
只要集合保持不變
下需是一個具體的實現IEnumerator接口的對像
Imports System
Public Class IteratorProduct : Implements System
Private Products As Collection
Private item As Integer =
Public Sub New()
Products = New Collection
Products
Products
Products
End Sub
Overridable ReadOnly Property Current() As Object
Get
Return Products(item)
End Get
End Property
Public Overridable Function MoveNext() As Boolean
item +=
End Function
Overridable Sub Reset()
item =
End Sub
Overridable Function GetEnumerator() As IEnumerator Implements IEnumerable
Return Me
End Function
End Class
Private Sub Page_Load(ByVal sender As System
Dim Products As IteratorProduct
Products = New IteratorProduct
Dim ProductName As String
For Each ProductName In Products
Response
Response
Next
End Sub
輸出為:
xh
lj
qd
說明實現成功
From:http://tw.wingwit.com/Article/program/net/201311/13669.html