本文整理汇总了VB.NET中System.Array.SetValue方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Array.SetValue方法的具体用法?VB.NET Array.SetValue怎么用?VB.NET Array.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesArray
Public Class SamplesArray
Public Shared Sub Main()
' Creates and initializes a one-dimensional array.
Dim myArr1(4) As [String]
' Sets the element at index 3.
myArr1.SetValue("three", 3)
Console.WriteLine("[3]: {0}", myArr1.GetValue(3))
' Creates and initializes a two-dimensional array.
Dim myArr2(5, 5) As [String]
' Sets the element at index 1,3.
myArr2.SetValue("one-three", 1, 3)
Console.WriteLine("[1,3]: {0}", myArr2.GetValue(1, 3))
' Creates and initializes a three-dimensional array.
Dim myArr3(5, 5, 5) As [String]
' Sets the element at index 1,2,3.
myArr3.SetValue("one-two-three", 1, 2, 3)
Console.WriteLine("[1,2,3]: {0}", myArr3.GetValue(1, 2, 3))
' Creates and initializes a seven-dimensional array.
Dim myArr7(5, 5, 5, 5, 5, 5, 5) As [String]
' Sets the element at index 1,2,3,0,1,2,3.
Dim myIndices() As Integer = {1, 2, 3, 0, 1, 2, 3}
myArr7.SetValue("one-two-three-zero-one-two-three", myIndices)
Console.WriteLine("[1,2,3,0,1,2,3]: {0}", myArr7.GetValue(myIndices))
End Sub
End Class
输出:
[3]: three [1,3]: one-three [1,2,3]: one-two-three [1,2,3,0,1,2,3]: one-two-three-zero-one-two-three
示例2: MainClass
' 导入命名空间
Imports System
Public Class MainClass
Shared Sub Main()
Dim anArray As Array
Dim l(0) As Integer
Dim lowerBounds(0) As Integer
l(0) = 7
lowerBounds(0) = 1995
'creates an array of objects numbered 1995 - 2002
anArray = Array.CreateInstance(GetType(System.Int32), l, lowerBounds)
anArray.SetValue(200000, 1995)
anArray.SetValue(1000000, 2001)
Console.WriteLine("The entry in position 1995 is " & _
(anArray.GetValue(1995).ToString))
Console.WriteLine("The entry in position 2002 is " & _
(anArray.GetValue(2001).ToString))
End Sub
End Class