Search code examples
c#c#-8.0default-interface-member

abstract interface methods in C# 8 preview


I try:

public interface I { abstract void F(); }

I get:

The modifier 'abstract' is not valid for this item in C# 7.3. Please use language version 'preview' or greater.

However I can find no mention of this feature ie in https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8

Where can I find the docs for that ? or is the message wrong here ?


Solution

  • C# 8.0 will allow modifiers and default implementations for interface members. You can see discussion here and details here

    However, the abstract modifier in an interface method makes zero sense IMO, but it might be available in the C# 8, since other modifiers will be valid as well.

    You can see the abstract is listed in the allowed modifiers

    The syntax for an interface is relaxed to permit modifiers on its members. The following are permitted: private, protected, internal, public, virtual, abstract, sealed, static, extern, and partial.