(我试过
this question,但是这段代码可以更好地隔离问题.)
我有这个代码:
Public Shared Sub PopulateTextFields(ByRef stuffList As List(Of Stuff)) Dim aStuff As New Stuff For Each aStuff In stuffList DoStuff(aStuff) Next End Sub Private Sub DoStuff(ByRef theStuff as Stuff) .... End Sub
Cannot refer to an instance member of
a class from within a shared method or
shared member initializer without an
explicit instance of the class.
在编写Dim语句时,我没有得到Stuff的显式实例吗?
不明白什么是错的.提前致谢!
我认为问题在于子程序DoStuff.如果你的潜艇都在同一个类中,你试图从PopulateTextFields中引用DoStuff,这是一个共享子.
为了实现这一点,您还需要将DoStuff声明为Shared.