2

Just a quick question for a learner.

What benefits does adding me. to things have?

Example me.picturebox1.imagelocation... vs picturebox1.imagelocation.

Michael Parr
  • 134
  • 3
  • 14

4 Answers4

2

Not a lot really. The only time it is essential is if there's a local variable with the same name as a property or field. The better solution would be to rename one or the other.

harriyott
  • 10,505
  • 10
  • 64
  • 103
1

me is the instance of the current class. it's not necessary to add but sometimes you need it to make a clear difference for the compiler. e.g. in the constructor if the parameter have the same name as the class variable you'd like to initialize! in c# (this):

class Class
{
    private int number;

    public Class(int number)
    {
        this.number = number;
    }
}
Yami
  • 1,405
  • 1
  • 11
  • 16
0

It's useful when you have local variable with the same name as type property or field.

There is the same problem with this in C#, and it's quite well answered here: When do you use the “this” keyword?

Community
  • 1
  • 1
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
0

I think i would help the system to understand which control should be executed when you have more than one form. For example, in 2 forms, you have the same textbox called txtFirstname, the system might not be able to understand which textbox should be used to capture value when needed. Using me.txtFirstname will specify that the textbox in the currently coded form will be used. I hope i've given you the correct answer because that's how i use me. until now