Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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/1/vb.net/16.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
指定在.net中实现2个接口的变量_.net_Vb.net_Clr - Fatal编程技术网

指定在.net中实现2个接口的变量

指定在.net中实现2个接口的变量,.net,vb.net,clr,.net,Vb.net,Clr,是否可以在.net中实现具有2个接口的类型说明符?比如: Public Sub New(obj as ICollection and INotifyCollectionChanged) ''Initialize Code End Sub 不,您必须定义一个从两个所需接口继承的接口 Public Interface IMyCombinedInterface Inherits IColllection, INotifyCollectionChanged End Interface

是否可以在.net中实现具有2个接口的类型说明符?比如:

Public Sub New(obj as ICollection and INotifyCollectionChanged)
    ''Initialize Code
End Sub

不,您必须定义一个从两个所需接口继承的接口

Public Interface IMyCombinedInterface
    Inherits IColllection, INotifyCollectionChanged

End Interface

您可以使用通用约束;例如在c#中:

publicsvoid某物(T obj)
其中T:IFoo,IBar
{....}

然后,只有当
value
被输入为同时实现
IFoo
IBar
的东西时,
Something(value)
才会起作用。谢谢Jon。如果我实现IMyCombindeInterface,我就不能向构造函数发送标准的ObservableCollection,因为它没有实现IMyCombindeInterface。是语言的限制,还是我遗漏了什么?谢谢马克,这正是我需要的。在Vb.net中,可以在花括号内添加多个约束。显然,只有在定义泛型类型时才能看到。在尝试传递给函数时不是这样。也就是说,您不能这样做:
公共函数Foo(x为{iBar,iBaz})为布尔值
public void Something<T>(T obj)
    where T : IFoo, IBar
{....}