如何在vb.net中将变量声明为给定类型
请帮助我解决这个小任务:如何将变量声明为给定类型。在本例中,为-interface 我想答案很简单,但我不知道,谷歌也不知道。 我什么都试过了,但解决不了 多谢各位如何在vb.net中将变量声明为给定类型,vb.net,interface,declare,Vb.net,Interface,Declare,请帮助我解决这个小任务:如何将变量声明为给定类型。在本例中,为-interface 我想答案很简单,但我不知道,谷歌也不知道。 我什么都试过了,但解决不了 多谢各位 公共接口IMyInterface 财产我的财产 端接口 公共子MySimpleSub() Dim tType As System.Type=GetType(IMyInterface) 调用子访问接口(tType) 端接头 公共子访问接口(ByVal t类型为System.Type) Dim arrMyArray()作为tType=
公共接口IMyInterface
财产我的财产
端接口
公共子MySimpleSub()
Dim tType As System.Type=GetType(IMyInterface)
调用子访问接口(tType)
端接头
公共子访问接口(ByVal t类型为System.Type)
Dim arrMyArray()作为tType={}如果要将类/结构/接口的类型传递给函数,可以如下模板化函数:
Public Sub SubAcceptsInterface(Of tType)()
Dim arrMyArray() As tType = {} 'This should declare fine
End Sub
Public Sub MySimpleSub()
SubAcceptsInterface(Of IMyInterface)()
End Sub
按如下方式传递模板的tType参数:
Public Sub SubAcceptsInterface(Of tType)()
Dim arrMyArray() As tType = {} 'This should declare fine
End Sub
Public Sub MySimpleSub()
SubAcceptsInterface(Of IMyInterface)()
End Sub
你可能想要一个新的。你应该在你的代码中描述这个接口的用途,以及你试图解决的实际问题(而不是你想解决的问题)。这是一个插件系统。我有几个步骤要处理数据库的smth:导出、导入记录等。GetType(IMyInterface)
将始终是IMyInterface
。您想要实现IMyInterface
的类型吗?我简化了这部分代码。这样声明是没有问题的:Dim arrMyArray()作为IMyInterface={},但在这种情况下,我将为每个接口编写几乎相同的代码