当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Array.CreateInstance方法代码示例

本文整理汇总了VB.NET中System.Array.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Array.CreateInstance方法的具体用法?VB.NET Array.CreateInstance怎么用?VB.NET Array.CreateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Array的用法示例。


在下文中一共展示了Array.CreateInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Main

Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a one-dimensional Array of type Int32.
        Dim my1DArray As Array = Array.CreateInstance(GetType(Int32), 5)
        Dim i As Integer
        For i = my1DArray.GetLowerBound(0) To my1DArray.GetUpperBound(0)
            my1DArray.SetValue(i + 1, i)
        Next i 
        ' Displays the values of the Array.
        Console.WriteLine("The one-dimensional Array contains the " _
           + "following values:")
        PrintValues(my1DArray)
        
    End Sub
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength((myArr.Rank - 1))
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:34,代码来源:Array.CreateInstance

输出:

The one-dimensional Array contains the following values:
1    2    3    4    5

示例2: Main

Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a multidimensional Array of type String.
        Dim myLengthsArray() As Integer = {2, 3, 4, 5}
        Dim my4DArray As Array = Array.CreateInstance(GetType(String), myLengthsArray)
        Dim i, j, k, l As Integer
        Dim myIndicesArray() As Integer
        For i = my4DArray.GetLowerBound(0) To my4DArray.GetUpperBound(0)
            For j = my4DArray.GetLowerBound(1) To my4DArray.GetUpperBound(1)
                For k = my4DArray.GetLowerBound(2) To my4DArray.GetUpperBound(2)
                    For l = my4DArray.GetLowerBound(3) To my4DArray.GetUpperBound(3)
                        myIndicesArray = New Integer() {i, j, k, l}
                        my4DArray.SetValue(Convert.ToString(i) + j.ToString() _
                           + k.ToString() + l.ToString(), myIndicesArray)
                    Next l
                Next k 
            Next j
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The four-dimensional Array contains the following values:")
        PrintValues(my4DArray)
    End Sub
    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The four-dimensional Array contains the following values:
'     0000    0001    0002    0003    0004
'     0010    0011    0012    0013    0014
'     0020    0021    0022    0023    0024
'     0030    0031    0032    0033    0034
'     0100    0101    0102    0103    0104
'     0110    0111    0112    0113    0114
'     0120    0121    0122    0123    0124
'     0130    0131    0132    0133    0134
'     0200    0201    0202    0203    0204
'     0210    0211    0212    0213    0214
'     0220    0221    0222    0223    0224
'     0230    0231    0232    0233    0234
'     1000    1001    1002    1003    1004
'     1010    1011    1012    1013    1014
'     1020    1021    1022    1023    1024
'     1030    1031    1032    1033    1034
'     1100    1101    1102    1103    1104
 '    1110    1111    1112    1113    1114
'     1120    1121    1122    1123    1124
'     1130    1131    1132    1133    1134
'     1200    1201    1202    1203    1204
'     1210    1211    1212    1213    1214
'     1220    1221    1222    1223    1224
'     1230    1231    1232    1233    1234
开发者ID:VB.NET开发者,项目名称:System,代码行数:71,代码来源:Array.CreateInstance

示例3: Main

Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a two-dimensional Array of type String.
        Dim my2DArray As Array = Array.CreateInstance(GetType(String), 2, 3)
        Dim i, j As Integer        
        For i = my2DArray.GetLowerBound(0) To my2DArray.GetUpperBound(0)
            For j = my2DArray.GetLowerBound(1) To my2DArray.GetUpperBound(1)
                my2DArray.SetValue("abc" + i.ToString() + j.ToString(), i, j)
            Next j 
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The two-dimensional Array contains the " _
           + "following values:")
        PrintValues(my2DArray)
    End Sub   
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:36,代码来源:Array.CreateInstance

输出:

The two-dimensional Array contains the following values:
abc00    abc01    abc02
abc10    abc11    abc12

示例4: Main

Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a multidimensional Array of type String.
        Dim myLengthsArray() As Integer = {3, 5}
        Dim myBoundsArray() As Integer = {2, 3}
        Dim myArray As Array = Array.CreateInstance(GetType(String), _
           myLengthsArray, myBoundsArray)
        Dim i, j As Integer
        Dim myIndicesArray() As Integer
        For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
            For j = myArray.GetLowerBound(1) To myArray.GetUpperBound(1)
                myIndicesArray = New Integer() {i, j}
                myArray.SetValue(i.ToString() + j.ToString(), myIndicesArray)
            Next j
        Next i
        
        ' Displays the lower bounds and the upper bounds of each dimension.
        Console.WriteLine("Bounds:" + ControlChars.Tab + "Lower" _
           + ControlChars.Tab + "Upper")
        For i = 0 To myArray.Rank - 1
            Console.WriteLine("{0}:" + ControlChars.Tab + "{1}" _
               + ControlChars.Tab + "{2}", i, myArray.GetLowerBound(i), _
               myArray.GetUpperBound(i))
        Next i
        
        ' Displays the values of the Array.
        Console.WriteLine("The Array contains the following values:")
        PrintValues(myArray)
    End Sub    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:49,代码来源:Array.CreateInstance

输出:

Bounds:    Lower    Upper
0:    2    4
1:    3    7
The Array contains the following values:
23    24    25    26    27
33    34    35    36    37
43    44    45    46    47

示例5: Main

Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a three-dimensional Array of type Object.
        Dim my3DArray As Array = Array.CreateInstance(GetType(Object), 2, 3, 4)
        Dim i As Integer
        For i = my3DArray.GetLowerBound(0) To my3DArray.GetUpperBound(0)
            Dim j As Integer
            For j = my3DArray.GetLowerBound(1) To my3DArray.GetUpperBound(1)
                Dim k As Integer
                For k = my3DArray.GetLowerBound(2) To my3DArray.GetUpperBound(2)
                    my3DArray.SetValue("abc" + i.ToString() _
                       + j.ToString() + k.ToString(), i, j, k)
                Next k 
            Next j
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The three-dimensional Array contains the " _
           + "following values:")
        PrintValues(my3DArray)
    End Sub
    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:42,代码来源:Array.CreateInstance

输出:

The three-dimensional Array contains the following values:
abc000    abc001    abc002    abc003
abc010    abc011    abc012    abc013
abc020    abc021    abc022    abc023
abc100    abc101    abc102    abc103
abc110    abc111    abc112    abc113
abc120    abc121    abc122    abc123

示例6: Arrays

Option Strict On

Public Module Arrays
   Public Sub Main
      Dim arr As Array
      Dim int() As Integer = {12, 16, 20, 24, 28, 32}
      arr = CType(int, Array)

      Dim byFours() As Integer = {12, 24, 36, 48}
      Dim names() As String = {"K", "S", "S", "D", "N"}
      Dim miscData() As Object = {"this", 12d, 16ui, "a"c}
      Dim objArray() As Object

      miscData = names
      
      Dim myArray1a() As Integer ' Uninitialized array
      Dim myArray1b As Integer() ' Uninitialized array
      Dim myArray2(10) As Integer ' 1-dimensional array with 11 elements

      Dim Employees1( , ) As Object ' Uninitialized 2-D array
      Dim Employees(200, 2) As Object ' 2-D array with 201 and 3 elements

      Dim jagged1(9)() As String
      Dim jagged2()() As String = New String(9)() {}

      Dim myArray1arr As Array
      Dim myArray2a As Array = Array.CreateInstance(GetType(Integer), 10)
      Dim members() As Integer = {3, 10}
      Dim myArray3a As Array = Array.CreateInstance(GetType(Integer), members)
   End Sub
End Module
开发者ID:VB程序员,项目名称:System,代码行数:31,代码来源:Array.CreateInstance


注:本文中的System.Array.CreateInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。