Override Object.ToString : ToString « Class « VB.Net

Override Object.ToString

Override Object.ToString
Imports System

Public Class MainClass
    Shared Sub Main()
         Dim i As Integer = 5
         Console.WriteLine("The value of i is: {0}", i.ToString(  ))

         Dim milo As New Dog(62)
         Console.WriteLine("My dog Milo weighs {0} pounds", milo.ToString(  ))
    End Sub
End Class

 Public Class Dog

     Private weight As Integer
     Public Sub New(ByVal weight As Integer)
         Me.weight = weight
     End Sub 'New

     Public Overrides Function ToString(  ) As String
         Return weight.ToString(  )
     End Function 'ToString

 End Class 'Dog


Related examples in the same category

1.Override ToString Method to provide meaningful informationOverride ToString Method to provide meaningful information
2.Override ToString functionOverride ToString function