Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Structure overrides ToString method

Imports System Public Class MainClass          Shared Sub Main()         Dim loc1 As Location           loc1.XVal = 75         loc1.YVal = 225         ' display the values in the structure         Console.WriteLine("Loc1 location: {0}", loc1)     End Sub End Class       Public Structure Location          Private myXVal As Integer          Private myYVal As Integer          Public Sub New( _             ByVal xCoordinate As Integer, ByVal yCoordinate As Integer)              myXVal = xCoordinate              myYVal = yCoordinate          End Sub 'New          Public Property XVal(  ) As Integer              Get                  Return myXVal              End Get              Set(ByVal Value As Integer)                  myXVal = Value              End Set          End Property          Public Property YVal(  ) As Integer              Get                  Return myYVal              End Get              Set(ByVal Value As Integer)                  myYVal = Value              End Set          End Property          Public Overrides Function ToString(  ) As String              Return String.Format("{0}, {1}", XVal, YVal)          End Function       End Structure