开发者

Specify a variable implementing 2 interfaces in .net

开发者 https://www.devze.com 2023-02-16 06:54 出处:网络
Is is possible to implement a type specifier with 2 interfaces in .net?Something like: Public Sub New(obj as ICollection and INoti开发者_StackOverflowfyCollectionChanged)

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

精彩评论

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