Use 'ME.' or not?

  • Thread starter Thread starter Bruce D
  • Start date Start date
B

Bruce D

I've just begun to write my third VB.NET program and I thought I should ask
the simple question...

Should I be using me.txtname.text or txtname.text? Most of my programs are
using the ME. prefix when referring to the objects on a form. I know it's
the same thing. I find it easier to read using "me." but I want my code to
be as efficient as possible. I did a quick Google, but found nothing. Are
there performance issues or is it only a preference?

Just wanted the groups $.02

-bruce duncan
 
One difference is that you dont have to type the full name if you start with
Me.

Best Regards,
Alejandro Lapeyre
 
Think that both syntax is compiled to the same result.

It can happen that you have 2 variables with the same name but different
scope:
strTest = member variable of class.
strTest = local variable of function in that class.
Inside that function, 'Me.strTest' is not 'strTest'. In this case, if you
force yourself to always use 'me', you wont make a mistake here.
Obviously it's best to prevent multiple variables with same name.

I can imagine that some programmers prefer code to be as short as possible,
and leave out 'me'.
 
The auto generated code uses Me , and i myself think it is verry handy (
saves me some typing ) i can`t think of a reasson not to use it
 
Bruce D said:
I've just begun to write my third VB.NET program and I thought I should
ask
the simple question...

Should I be using me.txtname.text or txtname.text? Most of my programs
are
using the ME. prefix when referring to the objects on a form. I know it's
the same thing. I find it easier to read using "me." but I want my code
to
be as efficient as possible. I did a quick Google, but found nothing.
Are
there performance issues or is it only a preference?

There is no performance difference between specifying 'Me' or omitting it.
However, sometimes 'Me' will be required to resolve a name clash. I always
use 'Me' because it gives me easy access to the form's members in
IntelliSense and helps me to write code in less time :-).
 

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

Back
Top