2

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

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

2 Answers 2

6

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

Public Interface IMyCombinedInterface
    Inherits IColllection, INotifyCollectionChanged

End Interface
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Jon. If I implement IMyCombinedInterface, I cant send in a standard ObservableCollection to the constructor because it doesn't implement IMyCombindeInterface. Is a limitation of the language, or am I missing something?
4

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.

2 Comments

Thanks Mark, this is exactly what I need. In Vb.net you can add the multiple constraints inside curly braces. See geekswithblogs.net/TechnicalDebtor/archive/2008/11/18/…
Apparently only when defining a Generic type. Not when trying to pass to a function. I.e. you can't do this: Public Function Foo(x as {iBar, iBaz}) As Boolean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.