
正文
vb.net数组末位 vb数组中某一个数出现的位置
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net 数组怎么自动定义维数
动态数组一般开始不能直接写dim a as string。除非Variant。一般先定义类型 但是数组名后得加上括号。例如
DIM a() AS STRING
后面根据需要使用的时候,可以自己定义大小。但是必须注意一点。重新定义的时候,
Redim a(11) 的时候,就会将原来的数组元素清空了,没有保存。
Redim Preserve a(11) 就会将重新定义数组大小的同时,还将原来的数据保存了。
相关问答
Q1: vb.net 数组的定义方法
1、点击VS工具。
2、打开后,新建一个Windows窗体应用程序。
3、新建完毕后,如图所示。
4、拖动一个按钮。
5、定义数组最常见的方法,如图示。
6、运行后,点击按钮,弹出提示正常。
7、定义数组第二种方法,属于动态的方法。
8、运行后,点击按钮,数组成功输出。
Q2: vb.net 多维数组怎么表示
array(2,2)是多维数组的访问方式,其数组的定义和初始化方法为:
Dim array As Integer(,) = {{1, 2, 3}, {4, 5, 6}}
每一行的元素数量是固定且相等的。
array(2)(2)是交错数组(即数组的数组)的访问方式。也就是,你有一个数组,这个数组的每个元素也是数组。其数组的定义和初始化方法为:
Dim array As Integer()() = {New Integer() {1, 2, 3}, New Integer() {4, 5, 6, 7, 8}}
由于每个元素是独立的数组,所以交错数组每一行的元素数量不固定,且可以不等。
Q3: VB.NET数组的排序法?
如果vb.net数组末位你是从vb6刚过渡上vb。netvb.net数组末位,建议还是用冒泡排序法vb.net数组末位,容易理解。
如果你正努力学习vb。net的方法,推荐一个例子如下:
Imports System
Imports System.Collections
Public Class SamplesArray
Public Class myReverserClass
Implements IComparer
' Calls CaseInsensitiveComparer.Compare with the parameters reversed.
Function Compare(x As Object, y As Object) As Integer _
Implements IComparer.Compare
Return New CaseInsensitiveComparer().Compare(y, x)
End Function 'IComparer.Compare
End Class 'myReverserClass
Public Shared Sub Main()
' Creates and initializes a new Array and a new custom comparer.
Dim myArr As [String]() = {"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}
Dim myComparer = New myReverserClass()
' Displays the values of the Array.
Console.WriteLine("The Array initially contains the following values:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the default comparer.
Array.Sort(myArr, 1, 3)
Console.WriteLine("After sorting a section of the Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the reverse case-insensitive comparer.
Array.Sort(myArr, 1, 3, myComparer)
Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the default comparer.
Array.Sort(myArr)
Console.WriteLine("After sorting the entire Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the reverse case-insensitive comparer.
Array.Sort(myArr, myComparer)
Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")
PrintIndexAndValues(myArr)
End Sub 'Main
Public Shared Sub PrintIndexAndValues(myArr() As [String])
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine(" [{0}] : {1}", i, myArr(i))
Next i
Console.WriteLine()
End Sub 'PrintIndexAndValues
End Class 'SamplesArray
'This code produces the following output.
'
'The Array initially contains the following values:
' [0] : The
' [1] : QUICK
' [2] : BROWN
' [3] : FOX
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting a section of the Array using the default comparer:
' [0] : The
' [1] : BROWN
' [2] : FOX
' [3] : QUICK
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting a section of the Array using the reverse case-insensitive comparer:
' [0] : The
' [1] : QUICK
' [2] : FOX
' [3] : BROWN
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting the entire Array using the default comparer:
' [0] : BROWN
' [1] : dog
' [2] : FOX
' [3] : jumps
' [4] : lazy
' [5] : over
' [6] : QUICK
' [7] : the
' [8] : The
'
'After sorting the entire Array using the reverse case-insensitive comparer:
' [0] : the
' [1] : The
' [2] : QUICK
' [3] : over
' [4] : lazy
' [5] : jumps
' [6] : FOX
' [7] : dog
' [8] : BROWN
关于vb.net数组末位和vb数组中某一个数出现的位置的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







