Skip to content

Default interface implementation shouldn't be virtual #9434

Closed Answered by timcassell
Yoticc asked this question in Language Ideas
Discussion options

You must be logged in to vote

Not sure what you mean, DIMs are overridable, just not like that. Just remove the override keyword and it works.

struct Struct1Ex : Interface1
{
   public void Display() => Console.WriteLine("Struct1Ex");
}

https://sharplab.io/#v2:C4LgTgrgdgPgAgJgIwFgBQ6CSVgFMwBmAhgMa5IAEAbkQDYS4UC8FAJrsRLcABQDKwSCWBIAlAG50NergB0AEQCWAZwAOtIgE8eE9OkU58xMhWx5CpcugDe6CvYpwALBSVqN20cwB8jpAE4eACIzI0skIN00AF89NGVBCGEKASERChBTQwsyVDRbNAc4AGZHFzd1LR0fP0Cg1KSRAFEAD0jJGKA=

You can also implement it explicitly:

struct Struct1Ex : Interface1
{
   void Interface1.Display() => Console.WriteLine("Struct1Ex");
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Yoticc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants