MyBase versus Me

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Could somebody tell me what is the difference between MyBase and Me?
For example, should I use

Page_Init(....) Handles MyBase.Init

Or

Page_Init(....) Handles Me.Init

Thanks,
Miguel
 
MyBase gives you a reference to the base class (the class the current class
derives from) "Me" gives you a reference to the current class.
In C#, "base" and "this".
Peter
 
MyBase explictly calls the function from the base class.

Me calls the function from the current class.

The Handles example isn't a good one.

MyBase is particularly useful when you are overriding a base member.

public class Employee
private _employeeId as integer

public overridable function EmployeeCode() as string
return _employeeId.ToString()
end function
end class

public class Consultant
inherits Employee
private _consultantId integer

public overrides function EmployeeCode() as string
return MyBase.EmployeeCode() & _consultantId
end function
end class

MyBase let's you easily override an implementation without having to
re-write the code in the base method. You can do your stuff, then call
MyBase.XXX.

Karl
 
Back
Top