Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does 'Me' in VB.NET refer only to an instantiation of the type? Just occurred to me that since I can reference properties in my VB.NET class without using 'Me', that I don't see a reason for using it for this purpose. Will referencing the variable either way always refer to the actual stored value for the property at runtime?

share|improve this question
Me has the same purpose as this in C#; it is a way to unambiguously refer to the current instance. – Robert Harvey Oct 29 '12 at 21:29

From the Me documentation on MSDN:

The Me keyword behaves like either an object variable or a structure variable referring to the current instance.

The use case described is that of passing the current object to another one.

share|improve this answer
+1 for object variable, and no-one can beat an answer with strong reference to MSDN :) – Yusubov Oct 29 '12 at 23:29

There are two main pursoses for the Me keyword.

You can use it to unambiguously refer to a member of this class. This allows local variables to use the same name, though this is poor practice.

Public Class MeExample

    Public Sub New(Name As String)
        Me.Name = Name
    End Sub

    Public Property Name As String

And you can use it within the class to use this instance of the object as a parameter in a method call.

    Protected Overridable Sub OnNameChanged(e As EventArgs)
        NameChanged(Me, e)
    End Sub

    Public Event NameChanged As EventHandler
End Class

And to complete the example, here's the full implementation of the Name property so that it raises the NameChanged event.

    Public Property Name As String
            Return _Name
        End Get
        Set(value As String)
            If _Name <> value Then
                _Name = value
            End If
        End Set
    End Property
    Private _Name As String
share|improve this answer
Why using a local variable with the same name is a "poor practice"? – Marco Sulla Jun 14 at 15:28
@MarcoSulla, if you have a local and an instance variable with the same name, you may forget to write "Me" before it and accidentally use the wrong variable. Also, when reading, you might miss the fact there is a local variable with that name and assume the code is referring to the instance variable. If you can be unambiguous it will help everyone. – Hand-E-Food Jun 15 at 0:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.