
calling object methods on a variable with interface type
Hello,
When I tried it out, the run-time type of the variable implemented
ToString(), and that implementation is what gets called. The following
example prints "hello":
Imports System
Public Interface myFace
function bar() As String
End Interface
Public Class myImpl
Implements myFace
Function bar As String Implements myFace.bar
return "hello"
End Function
Public Overrides Function ToString() As String
return bar()
End Function
End Class
Module Main
Sub Main
Dim foo As MyFace = New myImpl()
Console.WriteLine(Ctype(foo, Object).ToString())
End Sub
End Module
Thanks for the reply,
Mitch
Quote:
> Hi Nick,
> Not sure that will help the original poster. If his interface does not
> contain overridden ToString() method, then Object's ToString() will be
> invoked, and it is hardly helpful.