Explicit C# interface implementation of interfaces that inherit from other interfaces

Posted by anthony on Stack Overflow See other posts from Stack Overflow or by anthony
Published on 2010-05-09T00:44:08Z Indexed on 2010/05/09 0:48 UTC
Read the original article Hit count: 520

Consider the following three interfaces:

interface IBaseInterface
{
    event EventHandler SomeEvent;
}

interface IInterface1 : IBaseInterface
{
    ...
}

interface IInterface 2 : IBaseInterface
{
    ...
}

Now consider the following class that implements both IInterface1 and IInterface 2:

class Foo : IInterface1, IInterface2
{
    event EventHandler IInterface1.SomeEvent
    {
        add { ... }
        remove { ... }
    }

    event EventHandler IInterface2.SomeEvent
    {
        add { ... }
        remove { ... }
    }
}

This results in an error because SomeEvent is not part of IInterface1 or IInterface2, it is part of IBaseInterface.

How can the class Foo implement both IInterface1 and IInterface2?

© Stack Overflow or respective owner

Related posts about c#

Related posts about interface