Home > Back-end >  VB.Net equivalent of "This" for Shared Methods
VB.Net equivalent of "This" for Shared Methods

Time:11-07

Public Class MyLongClassName

    Public Shared Name As String = "Ana"

    Public Shared Function GetName() As String
        Dim Name As String = "Beta"
        '... this is toooooo long
        Return MyLongClassName.Name
    End Function

    Public Shared Function GetName() As String
        Dim Name As String = "Beta"
        '... much better
        Return This.Name '<--- there is any keyword for this?
    End Function

End Class

I dont care only about long class names. Having a keyword to refer to the very class (like 'this' in static methods in Javascript) will be very useful along my journey.

CodePudding user response:

To refer to a shared member within a shared method of the same class, you only have 2 choices:

  1. Use the class name.
  2. Use no qualifier and avoid locals with the same name.

CodePudding user response:

The equivalent keyword is me. In place of This.

And this goes back to even VB days, and even VBA days

Thus

Return Me.Name
  • Related