Jacob Horbulyk
Jacob Horbulyk

Reputation: 2636

Method with a return type that implements multiple interfaces

Currently I have the following:

interface IMyInterfaceReturnType : IEnumerable<string>, IDisposable
{
}

interface IMyInterface
{
    IMyInterfaceReturnType MyInterfaceMethod();
}

Is there a way that I can alter the method signature of MyInterfaceMethod() such that I can express that I will return an object that is both IEnumerable and Disposable without creating an intermediate interface? Say:

interface IMyInterface
{
    IEnumerable<string>, IDisposable MyInterfaceMethod();
}

Upvotes: 3

Views: 1036

Answers (1)

gregkalapos
gregkalapos

Reputation: 3619

This can be done with generics:

interface IMyInterface<T> where T :IEnumerable<string>, IDisposable 
{
    T MyInterfaceMethod();
}

Upvotes: 1

Related Questions