Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在vb.net中将变量声明为给定类型_Vb.net_Interface_Declare - Fatal编程技术网

如何在vb.net中将变量声明为给定类型

如何在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=

请帮助我解决这个小任务:如何将变量声明为给定类型。在本例中,为-interface

我想答案很简单,但我不知道,谷歌也不知道。 我什么都试过了,但解决不了

多谢各位


公共接口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={},但在这种情况下,我将为每个接口编写几乎相同的代码