VB.net 泛型集合

程序代码 程序代码

Public Class MyGenericCollection(Of ItemType)

    ' 定义一个通用的集合
    Private Items As Collection(Of ItemType)

    ' 建立构造函数
    Public Sub New()
        Items = New Collection(Of ItemType)
    End Sub

    ' 返回集合中数据项的数量
    Public ReadOnly Property Count() As Integer
        Get
            Return Items.Count
        End Get
    End Property


    Public ReadOnly Property AllItems() As Collection(Of ItemType)
        Get
            Return Items
        End Get
    End Property

    ' 得到或设置一个特定的数据项
    Public Property Item(ByVal Index As Integer) As ItemType
        Get
            Return Items(Index)
        End Get
        Set(ByVal value As ItemType)
            Items(Index) = value
        End Set
    End Property

    ' 给集合添加新的数据项
    Public Sub Add(ByVal Value As ItemType)
        Items.Add(Value)
    End Sub

    ' 从集合中删除数据项
    Public Sub RemoveAt(ByVal Item As Int32)
        Items.RemoveAt(Item)
    End Sub

End Class



文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: 535
发表评论
昵 称:
密 码: 游客发言不需要密码.
验证码: 验证码
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭