本文整理汇总了VB.NET中System.ArraySegment<T>.ArraySegment构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET ArraySegment<T>构造函数的具体用法?VB.NET ArraySegment<T>怎么用?VB.NET ArraySegment<T>使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.ArraySegment<T>
的用法示例。
在下文中一共展示了ArraySegment<T>构造函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesArray
Public Class SamplesArray
Public Shared Sub Main()
' Create and initialize a new string array.
Dim myArr As String() = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}
' Display the initial contents of the array.
Console.WriteLine("The original array initially contains:")
PrintIndexAndValues(myArr)
' Define an array segment that contains the entire array.
Dim myArrSegAll As New ArraySegment(Of String)(myArr)
' Display the contents of the ArraySegment.
Console.WriteLine("The first array segment (with all the array's elements) contains:")
PrintIndexAndValues(myArrSegAll)
' Define an array segment that contains the middle five values of the array.
Dim myArrSegMid As New ArraySegment(Of String)(myArr, 2, 5)
' Display the contents of the ArraySegment.
Console.WriteLine("The second array segment (with the middle five elements) contains:")
PrintIndexAndValues(myArrSegMid)
' Modify the fourth element of the first array segment myArrSegAll.
myArrSegAll.Array(3) = "LION"
' Display the contents of the second array segment myArrSegMid.
' Note that the value of its second element also changed.
Console.WriteLine("After the first array segment is modified, the second array segment now contains:")
PrintIndexAndValues(myArrSegMid)
End Sub
Public Shared Sub PrintIndexAndValues(arrSeg As ArraySegment(Of String))
Dim i As Integer
For i = arrSeg.Offset To (arrSeg.Offset + arrSeg.Count - 1)
Console.WriteLine(" [{0}] : {1}", i, arrSeg.Array(i))
Next i
Console.WriteLine()
End Sub
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
End Class
输出:
The original array initially contains: [0] : The [1] : quick [2] : brown [3] : fox [4] : jumps [5] : over [6] : the [7] : lazy [8] : dog The first array segment (with all the array's elements) contains: [0] : The [1] : quick [2] : brown [3] : fox [4] : jumps [5] : over [6] : the [7] : lazy [8] : dog The second array segment (with the middle five elements) contains: [2] : brown [3] : fox [4] : jumps [5] : over [6] : the After the first array segment is modified, the second array segment now contains: [2] : brown [3] : LION [4] : jumps [5] : over [6] : the