Swap

  <Extension()>
  Sub Swap(Of T)(ByRef object1 As T, ByRef object2 As T)

    If object2 Is Nothing Then
      object1 = Nothing
    Else
      Dim originalObject1 = object1
      object1 = object2
      object2 = originalObject1
    End If

  End Sub
Example:
    string1.Swap(string2) 'Swaps string1 with string2
    myObj.Swap(Nothing) 'Sets myObj to Nothing
    listbox1.Swap(listbox2) 'Swaps two Listboxes with each other

Description

Swaps two variables/objects with each other

Details

  • Author: noxon
  • Submitted on: 3/5/2013 2:59:46 PM
  • Language: VB
  • Type: All Types
  • Views: 1737

Double click on the code to select all.

 

;