© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
9 replies
UnemployedNinja

✅ Default interface methods - Am I using them wrong?

I'm trying to learn when/where to properly use interfaces, and I don't understand why my default method doesn't work.

I have this:
public interface IMyInterface {
    string Name { get; set; }
    string JobTitle { get; set; }
    
    void Foo() { Console.WriteLine("Default Foo"); }
}

public class Person {
    public string Name { get; set; }
}

public class Employee : Person, IMyInterface {
    public string JobTitle { get; set; }
}
public interface IMyInterface {
    string Name { get; set; }
    string JobTitle { get; set; }
    
    void Foo() { Console.WriteLine("Default Foo"); }
}

public class Person {
    public string Name { get; set; }
}

public class Employee : Person, IMyInterface {
    public string JobTitle { get; set; }
}


Creating a new instance of
Employee
Employee
should give me access to
employee.Foo()
employee.Foo()
, but it doesn't.

Maybe I'm just overlooking something simple, but I don't understand :/
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Static interface methods
C#CC# / help
3y ago
❔ abstract class virtual methods vs default implementation interface
C#CC# / help
4y ago
Using a default implementation on an interface
C#CC# / help
2y ago
❔ i know i am wrong
C#CC# / help
3y ago