當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Array.SetValue方法代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:39,代碼來源:Array.SetValue

輸出:

[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
開發者ID:VB程序員,項目名稱:System,代碼行數:23,代碼來源:Array.SetValue


注:本文中的System.Array.SetValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。