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
.
精彩评论