Passes an ArraySegment<(Of <(T>)>) structure to a method. : ArraySegment « Data Structure « VB.Net






Passes an ArraySegment<(Of <(T>)>) structure to a method.

  

Imports System

Public Class SamplesArray
    Public Shared Sub Main()
         Dim myArr As String() =  {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}

         PrintIndexAndValues(myArr)

         Dim myArrSegAll As New ArraySegment(Of String)(myArr)
         PrintIndexAndValues(myArrSegAll)


        Dim myArrSegMid As New ArraySegment(Of String)(myArr, 2, 5)

        PrintIndexAndValues(myArrSegMid)

        myArrSegAll.Array(3) = "LION"

        PrintIndexAndValues(myArrSegMid)

    End Sub 'Main

    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
    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
    End Sub
End Class

   
    
  








Related examples in the same category