-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Let's say I have the following rather contrived scenario:
interface I0
{
string Method()
{
return "I0";
}
}
interface I1 : I0
{
string I0.Method()
{
return "I1";
}
}
interface I2 : I0
{
string I0.Method()
{
return "I2";
}
}
Now I want a class to implement both I1 and I2:
class C12 : I1, I2
{
}
As expected, I get the following compiler error:
> Interface member 'I0.Method()' does not have a most specific implementation. Neither 'I1.I0.Method()', nor 'I2.I0.Method()' are most specific.
I can resolve this if I provide my own implementation. Inside it, how could I invoke the implementation from one of the interfaces, e.g. I1? I'm pretty sure the following syntax used to work in a previous preview:
class C12 : I1, I2
{
string I0.Method()
{
return base(I1).Method();
}
}
However, now the compiler complains:
> Use of keyword 'base' is not valid in this context
What is the correct syntax to invoke the default method implementation in interface I1? I can't find it documented anywhere.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: c790425e-da4e-9a75-6a11-f72109ce8d6a
- Version Independent ID: 09298e41-8f5a-c3c3-a849-8de67f8efba1
- Content: Safely update interfaces using default interface members in C#
- Content Source: docs/csharp/tutorials/default-interface-members-versions.md
- Product: dotnet-csharp
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn