Implements IEnumerable

Implements 关键字:用于对类成员实现特定接口进行界定。实现IEnumerable接口可以提供for each功能。

关于IEnumerable接口,MSDN相关说明如下:

IEnumerator 接口

公共属性

公共属性Current

受 .NET Framework 精简版的支持。

获取集合中的当前元素。
公共方法
公共方法MoveNext

受 .NET Framework 精简版的支持。

将枚举数推进到集合的下一个元素。
公共方法Reset

受 .NET Framework 精简版的支持。

将枚举数设置为其初始位置,该位置位于集合中第一个元素之前。

 

一个实现该接口的例子:

Public Class ChildFormEnumerator
    Implements IEnumerator

    Private mintIndex As Integer
    Private slEnum As SortedList

    ' The constructuor accepts one argument; the SortedList to enumerate.
    Public Sub New(ByVal sl As SortedList)
        slEnum = sl
        mintIndex = -1
    End Sub

    ' The Current property returns the form from the list
    ' using the index value.
    Public ReadOnly Property Current() As Object Implements IEnumerator.Current
        Get
            Return slEnum.GetByIndex(mintIndex)
        End Get
    End Property

    ' MoveNext returns True if more items exist in the list
    ' to be enumerated, and False otherwise.
    Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
        If mintIndex >= slEnum.Count - 1 Then
            Return False
        Else
            mintIndex += 1
            Return True
        End If
    End Function

    ' Reset the enumerator so that the current position is one
    ' item before the first item in the list.
    Public Sub Reset() Implements IEnumerator.Reset
        mintIndex = -1
    End Sub

End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值