473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Difference between MyBase and Me

Hi,

i came across custom usercontrols in VB 2005 and i'm not clear about
the difference between "Me" and "MyBase".

1. What is the difference between the two keywords in a UserControl.

2. Even if they are different, is there any harm in using it
interchangeably?

3. Where do we use "Me" and where do use "MyBase" in a UserControl.

Thanks in advance,
Sugan

Jul 7 '06 #1
4 11793
Sugan wrote:
i came across custom usercontrols in VB 2005 and i'm not clear about
the difference between "Me" and "MyBase".
"Me" refers to the current instance of a class. So code inside a Form
or UserControl can use Me to refer to the current instance.

"MyBase" refers to the base class, the class the the current class is
derived from. For example, Button is derived from Control. So if you
use Me you will refer to the button if you use MyBase, you will refer
to the Control class.

Jul 7 '06 #2
MyBase refers to the baseclass and it's implementation. Me refers to the
current class.

So if the base class has an overridable method Foo, and you override it in
the descendent. Then, when you say MyBase.Foo(), that will call the base
class's implementation. If you call Me.Foo(), it will call your
implementation in the descendent.

So yes, because they are different, there is harm in using them
interchangeable. You may call the wrong version of a method if you use the
wrong one, and wont' get the behavior your expect.

Use Me if you want to call an implementation in the current class. You
don't need to use it, if you just call Foo(), that is the same as Me.Foo().
If you want to specifically call the base class's version, then the only way
to do that is MyBase.Foo().

If the descendent does not override a method or property, then of course the
only implementation is in the base class, at which point it doesn't matter
which you use. But you don't want to get in the habit of having confusing
code, where it isn't clear what you are trying to call or accomplish. I
would say only use MyBase if you have overriden a method or property, but
specifically want to call the base class's version.

"Sugan" <vs****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi,

i came across custom usercontrols in VB 2005 and i'm not clear about
the difference between "Me" and "MyBase".

1. What is the difference between the two keywords in a UserControl.

2. Even if they are different, is there any harm in using it
interchangeably?

3. Where do we use "Me" and where do use "MyBase" in a UserControl.

Thanks in advance,
Sugan

Jul 7 '06 #3
Marina Levit [MVP] wrote:
MyBase refers to the baseclass and it's implementation. Me refers to the
current class.
Doesn't "Me" refer to the current instance of the class and "MyClass"
refer to the current class?

Jul 7 '06 #4
I meant to the current instance, my wording was off. I was just trying to
illustrate the difference between MyBase.Foo() and Me.Foo().

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Marina Levit [MVP] wrote:
>MyBase refers to the baseclass and it's implementation. Me refers to the
current class.

Doesn't "Me" refer to the current instance of the class and "MyClass"
refer to the current class?

Jul 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
1
by: Usman Ghani | last post by:
Hi There, I want to display below page creation time and so I have two variables as: Dim start_time As New DateTime Dim end_time As New DateTime First I am storing value in start_time on page...
5
by: TheBee | last post by:
Hello, I have seen the following routines in a class and don't understand how they work. For one, why two new() routines? Which is executed? Why not just use one routine? What does the mybase...
7
by: Bart_D | last post by:
Hi, Can anybody explain me what's the difference between for example: imports system.data implements ICallbackEventHandler inherits System.Web.UI.Page Thanks Bart
1
by: rn5a | last post by:
Often I come across the following Page_Load sub declaration in ASPX pages: Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Handles MyBase.Load ........ ........ End Sub What does...
1
by: pamelafluente | last post by:
Hi, I am not clear if there is there any difference in usage between Closing (mybase) and FormClosing ? Any advice on that ? -P
4
by: Academic | last post by:
I read the Help and some of the many Google hits I got but can't find out the difference between MyBase.Closing and MyBase.FormClosing Can anyone tell me? Thanks
2
by: shapper | last post by:
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
12
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.