开发者

Specify a variable implementing 2 interfaces in .net

Is is possible to implement a type specifier with 2 interfaces in .net? Something like:

Public Sub New(obj as ICollection and INoti开发者_StackOverflowfyCollectionChanged)
    ''Initialize Code
End Sub


No, you will have to define an interface that inherits from both of your desired interfaces.

Public Interface IMyCombinedInterface
    Inherits IColllection, INotifyCollectionChanged

End Interface


You can with generic constraints; for example in c#:

public void Something<T>(T obj)
    where T : IFoo, IBar
{....}

Then Something(value) will work only when value is typed as something that implements both IFoo and IBar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜