Generic Point Structure
Option Explicit On
Option Strict On
Module Program
Sub Main()
Dim intPt As New Point(Of Integer)(100, 100)
Console.WriteLine(intPt.ToString())
Dim dblPt As New Point(Of Double)(5.6, 3.23)
Console.WriteLine(dblPt.ToString())
Dim p1 As New Point(Of Integer)(10, 43)
Dim p2 As New Point(Of Integer)(6, 987)
Console.WriteLine(p1)
Console.WriteLine(p2)
Swap(Of Point(Of Integer))(p1, p2)
Swap(p1, p2)
Console.WriteLine(p1)
Console.WriteLine(p2)
End Sub
Public Function Swap(Of T)(ByRef a As T, ByRef b As T) As T
Console.WriteLine("T is a {0}.", GetType(T))
Dim temp As T
temp = a
a = b
b = temp
End Function
End Module
Public Structure Point(Of T)
Private xPos, yPos As T
Public Sub New(ByVal x As T, ByVal y As T)
xPos = x : yPos = y
End Sub
Public Property X() As T
Get
Return xPos
End Get
Set(ByVal value As T)
xPos = value
End Set
End Property
Public Property Y() As T
Get
Return xPos
End Get
Set(ByVal value As T)
yPos = value
End Set
End Property
Public Overrides Function ToString() As String
Return String.Format("({0}, {1})", xPos, yPos)
End Function
End Structure
Related examples in the same category