Mega Code Archive

 
Categories / VB.Net Tutorial / Data Type
 

Swap two integers without using a third

Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Collections Public Class Tester     Public Shared Sub Main                  Dim firstValue As Integer         Dim secondValue As Integer         firstValue = 17         secondValue = 123         Console.WriteLine("Before swap: {0}, {1}",firstValue, secondValue)         firstValue = firstValue Xor secondValue         secondValue = firstValue Xor secondValue         firstValue = firstValue Xor secondValue         Console.WriteLine("After swap: {0}, {1}",firstValue, secondValue)     End Sub End Class Before swap: 17, 123 After swap: 123, 17