C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Finally: We reverse only the first two elements by using the parameters 0 (the first index) and 2 (the count of elements to reverse).
Tip: Reverse is found on the Array type. It is a static (shared) function. We call it with a composite name.
SharedVB.NET program that reverses array
Module Module1
Sub Main()
Dim a() As Integer = {1, 4, 6, 10}
For Each v As Integer In a
Console.WriteLine(v)
Next
Console.WriteLine()
' Reverse entire array.
Array.Reverse(a)
For Each v As Integer In a
Console.WriteLine(v)
Next
Console.WriteLine()
' Reverse part of array.
Array.Reverse(a, 0, 2)
For Each v As Integer In a
Console.WriteLine(v)
Next
End Sub
End Module
Output
1
4
6
10
10
6
4
1
6
10
4
1
Tip: This is in unmanaged code. It is likely faster in most situations because of unmanaged optimizations.