N
Nathan R.
Hi,
I'm seeing something that seems extremely strange to me. All I'm
doing is overriding the toString method in one of my classes, so that
instances will display the way I'd like in Combo boxes and the like.
But instead of calling the overridden method of the subclass, it looks
like Object.toString is being called instead -- toString returns
"MyProjectName.MyClassName".
So that's strange and mysterious, but that's not the end of it. I
found a post on this group (URL
http://groups.google.com/groups?hl=...elVmkOjDHA.1688%40TK2MSFTNGP12.phx.gbl&rnum=4)
with a similar problem, and no real resolution. Using this, I reduced
the problem code to the following:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim joe As New Name("joe")
Dim obj As Object = joe
Debug.WriteLine(joe, "Joe")
Debug.WriteLine(obj, "Object")
End Sub
End Class
Public Class Name
Private ReadOnly m_name As String
Public Sub New(ByVal name As String)
m_name = name
End Sub
Public Overrides Function ToString() As String
Return m_name
End Function
End Class
The really strange bit? This works in a new project, but not in the
old. In the old, it gives the old behavior, calling Object.toString
instead. I'm running VB.NET 2002, but the above-referenced post
suggests VB.NET 2003 is equally susceptible to whatever this is.
Any ideas?
Thanks much!
Nathan
I'm seeing something that seems extremely strange to me. All I'm
doing is overriding the toString method in one of my classes, so that
instances will display the way I'd like in Combo boxes and the like.
But instead of calling the overridden method of the subclass, it looks
like Object.toString is being called instead -- toString returns
"MyProjectName.MyClassName".
So that's strange and mysterious, but that's not the end of it. I
found a post on this group (URL
http://groups.google.com/groups?hl=...elVmkOjDHA.1688%40TK2MSFTNGP12.phx.gbl&rnum=4)
with a similar problem, and no real resolution. Using this, I reduced
the problem code to the following:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim joe As New Name("joe")
Dim obj As Object = joe
Debug.WriteLine(joe, "Joe")
Debug.WriteLine(obj, "Object")
End Sub
End Class
Public Class Name
Private ReadOnly m_name As String
Public Sub New(ByVal name As String)
m_name = name
End Sub
Public Overrides Function ToString() As String
Return m_name
End Function
End Class
The really strange bit? This works in a new project, but not in the
old. In the old, it gives the old behavior, calling Object.toString
instead. I'm running VB.NET 2002, but the above-referenced post
suggests VB.NET 2003 is equally susceptible to whatever this is.
Any ideas?
Thanks much!
Nathan