Mega Code Archive

 
Categories / VB.Net Tutorial / Collections
 

Swap elements in an array

Public Class Tester     Public Shared Sub Main         Dim result As New System.Text.StringBuilder         Dim arraySwap() As String = {"A", "B", "C", "D", "E"}         Swap(arraySwap, 1, 3)         For Each fruit As String In arraySwap             Console.WriteLine(fruit)         Next fruit     End Sub     Public Shared Sub Swap(ByRef swapArray() As Object, _             ByVal first As Integer, ByVal second As Integer)         Dim tempObject As Object         tempObject = swapArray(first)         swapArray(first) = swapArray(second)         swapArray(second) = tempObject     End Sub End Class A D C B E