vb.net 对非共享成员的引用需要在调用 public sub 时发生对象引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13462479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reference to a non-shared member requires an object reference occurs when calling public sub
提问by Dave Mackey
I have a Public Class "General" in which is a Public Sub "updateDynamics". When I attempt to reference it in the code-behind for a page like so:
我有一个公共类“General”,其中是一个公共子“updateDynamics”。当我尝试在页面的代码隐藏中引用它时:
updateDynamics(get_prospect.dynamicsID)
I get the following error:
我收到以下错误:
reference to a non-shared member requires an object reference
对非共享成员的引用需要对象引用
回答by Tim Schmelter
You either have to make the method Shared
or use an instance of the class General
:
您必须创建方法Shared
或使用类的实例General
:
Dim gen = New General()
gen.updateDynamics(get_prospect.dynamicsID)
or
或者
General.updateDynamics(get_prospect.dynamicsID)
Public Shared Sub updateDynamics(dynID As Int32)
' ... '
End Sub
回答by Pastor Hampande
Go to the Declaration of the desired object and mark it Shared.
转到所需对象的声明并将其标记为共享。
Friend Shared WithEvents MyGridCustomer As Janus.Windows.GridEX.GridEX
朋友与事件共享 MyGridCustomer 作为 Janus.Windows.GridEX.GridEX