1
我得到这个错误: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.
从共享(或静态)函数调用等功能
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function ParseData() As String
Dim value as string = GetValue()
End Function
Private Function GetValue() as String
Return "halp"
End Function
End Class
我知道它是与第一功能是共享的,第二个函数大概应该是这样的事实公众也是如此,但我不完全理解它背后的原因。可能不相关,但我从一些JavaScript调用Web方法。
从我读过的WebMethods必须共享。这是我唯一的选择吗? – Radu 2010-08-20 04:28:23
我编辑过。基本上,是的,这是你唯一的选择。错误非常明显。由于“共享”方法的本质,也必须共享从共享方法调用的方法。 – 2010-08-20 04:31:44
我做了另一个编辑。在我的编辑中,您会注意到我创建了'Utilities'类的实例,以便我可以调用Public(但不是Shared)'GetValues'方法。 – 2010-08-20 04:39:54