The difference between MyClass and Me as it pertains to classes

  • Thread starter Thread starter Iced Crow
  • Start date Start date
Iced Crow,
MyClass refers specifically to the current class. Me refers to the current
object.

For example if I have:

Class BaseClass
Public Overridable Sub f1()
debug.writeline("BaseClass", "f1")
End Sub
End Class

Class Class1 : Inherits BaseClass
Public Sub DoSomething()
MyClass.F1()
Me.F1()
End Sub
Public Overrides Sub f1()
debug.writeline("Class1", "f1")
End Sub
End Class

Class Class2 : Inherits Class1
Public Overrides Sub f1()
debug.writeline("Class2", "f1")
End Sub
End Class

Dim c as New Class2
c.DoSomething()

The call to MyClass.F2 in Class1 will execute Class1.F1 although Class2
overrides it. As MyClass looks specifically at that class.
The call to Me.F2 in Class1 will execute Class2.F1 as Class2 overrides it,
as Me looks at the object itself.

Hope this helps
Jay
 
Back
Top