加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net 教程 1-11 ArrayList

发布时间:2020-12-17 07:34:56 所属栏目:百科 来源:网络整理
导读:ArrayList类与List(of T)的用法差不多,提供的方法也差不多。 Add():在结尾处添加数据 RemoveAt():移除指定位置的数据 Insert():在指定位置处插入数据 Clear():移除所有元素 属性: Count:返回包含的数据数量 与List(of T)不同的是,ArrayList可以包含

ArrayList类与List(of T)的用法差不多,提供的方法也差不多。

Add():在结尾处添加数据
RemoveAt():移除指定位置的数据
Insert():在指定位置处插入数据
Clear():移除所有元素

属性:

Count:返回包含的数据数量

与List(of T)不同的是,ArrayList可以包含任意类型的数据,但是相应的,要使用包含的数据,就必须对数据做转换。

如下例代码:

    Sub Main()
        Dim arrDate As New ArrayList

        Dim addString As String = "this is a test"
        Dim addInteger As Integer = 123
        Dim addDateTime As New DateTime(2017,3,20,10,10)

        arrDate.Add(addString)
        arrDate.Add(addInteger)
        arrDate.Add(addDateTime)

        Console.WriteLine("包含数据数量:" & arrDate.Count)

        Dim toString As String = CType(arrDate(0),String)
        Dim toInteger As Integer = CType(arrDate(1),Integer)
        Dim toDateTime As DateTime = CType(arrDate(2),DateTime)

        Console.WriteLine("数据1:{0}",toString)
        Console.WriteLine("数据2:{0}",toInteger)
        Console.WriteLine("数据3:{0}",toDateTime)

        Console.ReadKey()
    End Sub

运行结果如下:



由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读