Overriding Object.ToString()

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Probably a stupid question, but is there any way to create a class with a
custom ToString() method (or any overrideable method, for that matter) that
is called, even when an object of this class is cast back to Object?

Thanks in advance,

Dave Hagedorn
 
Joe,
Have you tried:

Public Class Joe

Public Overrides Function ToString() As String
Return "Says Hi!"
End Function

End Class

Dim joe As Object = New Joe()
Debug.WriteLine(joe.ToString(), "Joe")

Because I used the Overrides keyword on the ToString function, I am using
the Joe.ToString function even when I assign a Joe object to an Object
variable.

Hope this helps
Jay
 
Back
Top