2

有了这个:

  class outer
    public shared X as string = ""
    class inner
      public shared sub test()
        Dim s as string
        s = X ' refers to the shared (static) variable in outer
      end sub
    end class
  end class

测试方法中对 X 的引用是对外部类中声明的共享变量,但是,如果我的内部类使用该名称声明了一个变量(从外部类中删除共享变量),我如何访问它?

  class outer
    public shared X as string = ""
    class inner
      public X as string = "x"
      public shared sub test()
        Dim s as string
        s = X ' this fails because it's an attempt to access an instance variable
      end sub
    end class
  end class
4

1 回答 1

1

尝试指定外部类的名称,如下所示:

Class outer
    Public Shared X As String = "bar"

    Class inner
        Public X As String = "foo"
        Public Shared Sub test()
            Dim s As String = X             ' foo
            Dim t As String = outer.X       ' bar
        End Sub
    End Class
End Class
于 2013-05-03T23:19:25.300 回答