VB.Net 相当于共享方法的 "This"

VB.Net equivalent of "This" for Shared Methods

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

我不关心长 class 名字。有一个关键字来引用非常 class(如 Javascript 中静态方法中的 'this')将在我的旅程中非常有用。

等效关键字是我。代替这个。

这甚至可以追溯到 VB 天,甚至 VB 天

因此

Return Me.Name

编辑: 如前所述,我在共享 class 中不可用。那么就

Return Name

会很好地工作,

   Return MyLongClassName.Name

要在同一 class 的共享方法中引用共享成员,您只有 2 个选择:

  1. 使用 class 名称。
  2. 不使用限定符并避免使用相同名称的本地人。