interface inheritance without hiding

Sky*_*kyN 4 c#

If I write class, then all ok

class C
{
    protected int _attr;
    int attr { get { return _attr; } }
}

class CWithSet : C
{
    int attr { set { _attr = value; } }
}
Run Code Online (Sandbox Code Playgroud)

But, if I write interface

interface I
{
    int attr { get; }
}

interface IWithSet : I
{
    int attr { set; }
}
Run Code Online (Sandbox Code Playgroud)

then I have warring: "'IWithSet.attr' hides inherited member 'I.attr'. Use the new keyword if hiding was intended."

How to write, so as not to get warning?

Eri*_*sen 6

From the C# Specification: The inherited members of an interface are specifically not part of the declaration space of the interface. Thus, an interface is allowed to declare a member with the same name or signature as an inherited member. When this occurs, the derived interface member is said to hide the base interface member. Hiding an inherited member is not considered an error, but it does cause the compiler to issue a warning. To suppress the warning, the declaration of the derived interface member must include a new modifier to indicate that the derived member is intended to hide the base member. (Interface members) The correct implementation is:

interface IWithSet : I
{
    new int attr { get; set; }
}
Run Code Online (Sandbox Code Playgroud)