【问题标题】:In VB.net, How can I access to a function in a class from an other function in a nested class?在 VB.net 中,如何从嵌套类中的其他函数访问类中的函数?
【发布时间】:2015-02-27 16:11:24
【问题描述】:

我在 VB.net 中进行开发,但我来自 java,我想创建一个实现如下接口的匿名类:

int h = 4;

Object x = new iInterface({
    @Override void f(){
        h = 5;
    }
});

我不知道该怎么做,所以我想创建一个实现“iInterface”的嵌套类,但是......

Class N
    Dim h = 4
    Class n
        Implements iInterface
        Sub f()
            h = 5
        End Sub
    End Class
End Class

...VisualStudio 在 h 下放了一个毛茸茸的蓝色垫子,对我说:“对非共享成员的引用需要对象引用”

我该怎么办? >___

【问题讨论】:

    标签: vb.net interface nested-class


    【解决方案1】:

    类似这样的:

    Class N
    Shared h = 4
    Class n
        Implements iInterface
        Sub f()
            h = 5
        End Sub
    End Class
    

    结束类

    【讨论】:

      【解决方案2】:

      您可能正在寻找共享元素。这是相关文档:https://msdn.microsoft.com/en-us/library/zc2b427x.aspx 否则,您必须显式创建该类的实例才能 使用它。

      【讨论】:

        猜你喜欢
        • 2010-11-11
        • 1970-01-01
        • 2013-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多