Hi Richard,
The Me keyword is actually required in some situations.
In the example class below, Me is used to disambiguate between Sub New's
lastName parameter and the LastName property. Since the Sub New parameter
is named 'lastName' and the class includes a Property named 'LastName', Me
is necessary to ensure the assignment works correctly. NOTE: If you don't
use Me in this case no error will be generated but assignements will not
always work as expected.
me.LastName = lastName
Public Class Customer
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set (ByVal value As String)
me._LastName = value
End Set
End Property
Public Sub New(ByVal lastName As String)
me.LastName = lastName
End Sub
Public Sub ChangeLastName(ByVal lastName As String)
me.LastName = lastName
End Sub
End Class
We have a policy at my development company - we always use the Me keyword.
Why?
1. There is no penalty for using Me.
2. Using Me triggers intellisense that reinforces an object-oriented style
of programming. Many authors and experts call Me (and the C# equivalent:
This) the OOP syntax for referring to class members.
3. As shown in the example above, Me is required in some cases.
4. Me improves code readability - one can always tell when a class member is
being used v.s. a local variable, parameter, etc.
--
Mike
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,
I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.
Thanks,
Richard