数组和集合的初始及赋值
Posted VB.Net
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组和集合的初始及赋值相关的知识,希望对你有一定的参考价值。
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
VB.Net中数组和集合初始化以及赋值的常见代码如下:
数组:
'数组
'1
Dim a1() As Integer = {1, 2, 3, 4, 5}
'2
Dim a2 As Integer() = {1, 2, 3, 4, 5}
'3
Dim a3() As Integer = New Integer(4) {1, 2, 3, 4, 5}
'4
Dim a4 As Integer() = New Integer(4) {1, 2, 3, 4, 5}
'5 二维数组
Dim a5(,) As Integer = {{1, 2}, {3, 4}, {5, 6}}
'6 二维数组
Dim a6(,) As Integer = New Integer(2, 1) {{1, 2}, {3, 4}, {5, 6}}
'7 二维数组
Dim a7 As Integer(,) = New Integer(2, 1) {{1, 2}, {3, 4}, {5, 6}}
'8 二维数组
Dim a8 = {({1, 2, 3}), ({4, 5}), ({6})}
For i = 0 To a8.Length - 1
For j = 0 To a8(i).Length - 1
Console.Write(a8(i)(j) & " ")
Next
Console.WriteLine("")
Next
'https://blog.csdn.net/uruseibest
ArrayList:
'========= ArrayList ===========
'1
Dim alst1 As New ArrayList()
alst1.Add("12")
alst1.Add(34)
alst1.Add("56")
'2
Dim alstsample() As String = {"12", "34", "56"}
Dim alst2 As ArrayList = New ArrayList(alstsample)
'3
Dim alstsample1() As Object = {12, "ab", 34}
Dim alst3 As ArrayList = New ArrayList(alstsample1)
'4
Dim alst4 = New ArrayList() From {12, "ab", 34}
'5
Dim alst5 As New ArrayList()
alst5.AddRange(New String() {"12", "34", "56"})
'6
Dim alst6 As New ArrayList(New String() {"12", "34", "56"})
'7
Dim alst7 As New ArrayList(New Object() {"ab", 12, "34"})
'8
Dim alst8 As New ArrayList({12, "ab", 34})
'https://blog.csdn.net/uruseibest
List:
'=========== List =================
'1
Dim lst1 As New List(Of String)
lst1.Add("12")
lst1.Add("34")
lst1.Add("56")
'2
Dim lstsample() As String = {"12", "34", "56"}
Dim lst2 As List(Of String) = New List(Of String)(lstsample)
'3
Dim lst3 As List(Of String) = New List(Of String)(New String() {"12", "34", "56"})
'4
Dim lst4 As New List(Of String)
lst4.AddRange(New String() {"12", "34", "56"})
'5
Dim lst5 As New List(Of String)({"12", "34", "56"})
'6
Dim lst6 As New List(Of String) From {"12", "34", "56"}
'https://blog.csdn.net/uruseibest
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
以上是关于数组和集合的初始及赋值的主要内容,如果未能解决你的问题,请参考以下文章