Home All Groups Group Topic Archive Search About

Unexpected behaviour of MyClass (please ignore 1st post)

Author
11 Apr 2005 12:41 PM
Diana Mueller
Public Class Base
    Public Function Foo() As String
        Return MyClass.GetType.FullName
    End Function

End Class

Public Class Derrived
    Inherits Base
End Class

Why does Derrived.Foo() return "Derrived"? Shouldn't that be "Base"?

Author
11 Apr 2005 1:06 PM
Herfried K. Wagner [MVP]
"Diana Mueller" <no@spam> schrieb:
> Public Class Base
>    Public Function Foo() As String
>        Return MyClass.GetType.FullName
>    End Function
>
> End Class
>
> Public Class Derrived
>    Inherits Base
> End Class
>
> Why does Derrived.Foo() return "Derrived"? Shouldn't that be "Base"?

If you instantiate 'Derived' and call 'Foo' on this object, the object's
most specific type is 'Derived', and thus "Derived" is returned.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
11 Apr 2005 5:55 PM
Cor Ligthert
Diana,

Because you are doing a methnod which is in MyClass which returns the type
of the current instance and not from the used class

Than it would have been
Gettype(Base).FullName

I hope this helps,

Cor