Overrides ToString function : Object « Development « VB.Net






Overrides ToString function

 

Public Class Temperature
   Private temp As Decimal

   Public Sub New(temperature As Decimal)
      Me.temp = temperature
   End Sub

   Public Overrides Function ToString() As String
      Return Me.temp.ToString("N1") + " Degree"   
   End Function
End Class

Module Example
   Public Sub Main()
      Dim currentTemperature As New Temperature(23.6d)
      Console.WriteLine("The current temperature is {0}.", currentTemperature)
   End Sub
End Module

   
  








Related examples in the same category

1.Object Class Supports all classes in the .NET Framework class hierarchy
2.Object.Equals Method tells whether the specified Object is equal to the current Object.
3.Create your own Equals method
4.Create Equals method based on Equals method from fields
5.Create Complex Structure with Equals and GetHashCode method
6.Object.GetType Method Gets the Type of the current instance.
7.Object.MemberwiseClone Method Creates a shallow copy of the current Object.
8.Object Class Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes.
9.Object.GetType Method Gets the Type of the current instance.
10.Object.MemberwiseClone Method Creates a shallow copy of the current Object.
11.Object Class Supports all classes in the .NET Framework class hierarchy
12.Object.GetType Method Gets the Type of the current instance.
13.Object.MemberwiseClone Creates a shallow copy of the current Object.
14.No implementation. All members are inherited from Object