-
I plan to develop the project using Dotnet7(C#11.0)+VS2022(17.5.3), which requires the use of DIM (default interface method) language features. I can only find some examples in the relevant documents of c # 8.0. For example: On this page, I copied the following code: interface IA
{
void M() { WriteLine("IA.M"); }
}
interface IB : IA
{
override void IA.M() { WriteLine("IB.M"); } // explicitly named **CS0106 :The modifier 'override ' is not valid for this item**
}
interface IC : IA
{
override void M() { WriteLine("IC.M"); } // implicitly named **CS0106 :The modifier 'override ' is not valid for this item**
} My csproj file is as follows: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project> Visual studio prompted me with the following error: I guess the syntax above was valid when writing this document My question is: I want to use the dim feature under c # 11.0. Where can I get the syntax specification for the Default interface method in c # 11.0 version? The helpdocument lists many examples, some of which may have been invalidated in c # 11.0, which makes me very confused. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You were looking at proposal document, not the one describing implemented design. I've stumbled upon this too, once. Googling dims actually falsely leads to proposal document. Try this one. Note that implemented design has much narrower scope of what is allowed compared to that proposal doc. |
Beta Was this translation helpful? Give feedback.
You were looking at proposal document, not the one describing implemented design. I've stumbled upon this too, once. Googling dims actually falsely leads to proposal document.
Try this one. Note that implemented design has much narrower scope of what is allowed compared to that proposal doc.
https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/interface-implementation/default-interface-methods-versions