skip to Main Content
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.

2

Answers


  1. 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
    

    Edit:
    As pointed out, me is not available in a shared class. So then just

    Return Name
    

    Will work fine, and so will

       Return MyLongClassName.Name
    
    Login or Signup to reply.
  2. 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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search