Question

  • Thread starter Thread starter Don
  • Start date Start date
Me refers to the class where the the 'code' is currently executing, e.g.:

Friend Class AAA

Private m_bbb As Integer = 1

Public Sub New()

End Sub

Public ReadOnly Property BBB1() As Integer

Get
Return m_bbb
End Get

End Property

Public ReadOnly Property BBB2() As Integer

Get
Return Me.m_bbb
End Get

End Property

End Class

In this case, properties BBB1 and BBB2 of an instance of AAA will both
return 1. m_bbb is a private member of AAA with class-wide scope and, when
referenced within the class does not need to be further qualified, In the
get accessor of property BBB2, m_bbb is explicitly qualified and although it
is superflous it is still valid.

Me is often used to differentiate between 2 variables of different scope but
with the same name as in the following constructor for class AAA:

Public Sub New(m_bbb As Integer)

Me.m_bbb = m_bbb

End Sub

Unless the target of the assignment is qualified then the assignment
precedence would be to the most local variable and the parameter m_bbb would
be assigned the value from itself.

MyBase is used in conjunction with inheritance to access properties and
methods of the base object:

Friend Class AAA
Inherits XXX

Public Sub New()

MyBase.New()

'Constuction code for AAA here

End Sub

Public Overrides ReadOnly Property Count() As Integer

Get
Return MyBase.Count * 2
End Get

End Property

End Class

Here MyBase.New() is called in the constructor to ensure that the
constructor for the base class (XXX) is called before doing anything else.

Now assume that class XXX exposes a Count property. In class AAA we want the
Count property to be twice the normal value. To do this we override the
inherited Count property and in it's get accessor, we return the value of
the base class Count property (Mybase.Count) multiplied by 2.

I hope that's clearer than mud :)
 
Thanks will need some time to digest this one

Me refers to the class where the the 'code' is currently executing, e.g.:

Friend Class AAA

Private m_bbb As Integer = 1

Public Sub New()

End Sub

Public ReadOnly Property BBB1() As Integer

Get
Return m_bbb
End Get

End Property

Public ReadOnly Property BBB2() As Integer

Get
Return Me.m_bbb
End Get

End Property

End Class

In this case, properties BBB1 and BBB2 of an instance of AAA will both
return 1. m_bbb is a private member of AAA with class-wide scope and, when
referenced within the class does not need to be further qualified, In the
get accessor of property BBB2, m_bbb is explicitly qualified and although it
is superflous it is still valid.

Me is often used to differentiate between 2 variables of different scope but
with the same name as in the following constructor for class AAA:

Public Sub New(m_bbb As Integer)

Me.m_bbb = m_bbb

End Sub

Unless the target of the assignment is qualified then the assignment
precedence would be to the most local variable and the parameter m_bbb would
be assigned the value from itself.

MyBase is used in conjunction with inheritance to access properties and
methods of the base object:

Friend Class AAA
Inherits XXX

Public Sub New()

MyBase.New()

'Constuction code for AAA here

End Sub

Public Overrides ReadOnly Property Count() As Integer

Get
Return MyBase.Count * 2
End Get

End Property

End Class

Here MyBase.New() is called in the constructor to ensure that the
constructor for the base class (XXX) is called before doing anything else.

Now assume that class XXX exposes a Count property. In class AAA we want the
Count property to be twice the normal value. To do this we override the
inherited Count property and in it's get accessor, we return the value of
the base class Count property (Mybase.Count) multiplied by 2.

I hope that's clearer than mud :)
 
Back
Top