MyBase versus Me

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
 
G

Guest

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
 
K

Karl Seguin [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top