Exercise
Function swap reference parameters
Objetive
Write a Visual Basic (VB.Net) function named "Swap" to swap the values of two integer numbers, which are passed by reference.
An example of use might be:
int x=5, y=3;
Swap(ref x, ref y);
Console.WriteLine("x={0}, y={1}", x, y);
(which should write "x=3, y=5")
Code
Imports System
Public Class exercise106
Public Shared Sub Swap(ByRef x As Integer, ByRef y As Integer)
Dim swap As Integer
swap = x
x = y
y = swap
End Sub
Public Shared Sub Main()
Dim x As Integer = 5
Dim y As Integer = 3
Swap(x, y)
Console.WriteLine("x: {0} , y: {1}", x, y)
End Sub
End Class