⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortedpointlist.vb

📁 OOP With Microsoft VB.NET And Csharp Step By Step
💻 VB
字号:
Class SortedPointList
    Implements IEnumerable

    Public Sub New()
    End Sub

    Private m_points As New ArrayList()
    Public Sub AddRandomPoints(ByVal howMany As Integer, _
ByVal maximum As Integer)
        m_points.Clear()
        Dim rgen As New System.Random()
        Dim count As Integer
        For count = 0 To howMany - 1
            m_points.Add( _
                New SortablePoint(rgen.Next(maximum), rgen.Next(maximum)))
        Next
        m_points.Sort()
    End Sub


    Private Class PointEnumerator
        Implements IEnumerator

        Dim m_points As ArrayList
        Dim m_position As Integer = -1
        Dim m_initialCount As Integer

        Public Sub New(ByVal points As ArrayList)
            m_points = points
            m_initialCount = points.Count
        End Sub

        Public Sub Reset() Implements System.Collections.IEnumerator.Reset
            m_position = -1
        End Sub

        Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
            If (m_initialCount = m_points.Count) Then
                m_position += 1
                If (m_position >= m_points.Count) Then
                    Return False
                Else
                    Return True
                End If
            Else
                Throw New InvalidOperationException( _
                    "Collection has changed during enumeration.")
            End If
        End Function

        Public ReadOnly Property Current() As Object Implements System.Collections.IEnumerator.Current
            Get
                If (m_initialCount <> m_points.Count) Then
                    Throw New InvalidOperationException( _
                        "Collection has changed during enumeration.")
                ElseIf (m_position >= m_points.Count) Then
                    Throw New InvalidOperationException( _
                        "Enumeration value is invalid.")
                Else
                    Return m_points(m_position)
                End If
            End Get
        End Property
    End Class

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return New PointEnumerator(m_points)
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -