© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
196 replies
joren

❔ Defining base impl ctor in interface

So currently for some testing I have the following code:
    interface HumanInterface
    {
        public string Name { get; }
        public string Description { get; }

        public void walk() { Console.WriteLine("Default implementation"); }

        // Forcing implementing class to define scream()
        public void scream();
    }

    class Foo : HumanInterface
    {
        Foo(string name, string description)
        {
            Name = name;
            Description = description;
        }

        public string Name { get; }
        public string Description { get; }
        void HumanInterface.scream() { Console.WriteLine("Screams"); }
    }
    interface HumanInterface
    {
        public string Name { get; }
        public string Description { get; }

        public void walk() { Console.WriteLine("Default implementation"); }

        // Forcing implementing class to define scream()
        public void scream();
    }

    class Foo : HumanInterface
    {
        Foo(string name, string description)
        {
            Name = name;
            Description = description;
        }

        public string Name { get; }
        public string Description { get; }
        void HumanInterface.scream() { Console.WriteLine("Screams"); }
    }

my ctor
Foo
Foo
is pretty generic, in fact I'd probably want all my derived classes to have that exact ctor. How'd I achieve this?
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
Next page

Similar Threads

✅ Can i put constraint on ctor in interface
C#CC# / help
3y ago
❔ Cast is not valid when casting interface to comcrete impl
C#CC# / help
3y ago
❔ Default implementation of a `static abstract` base interface member in derived interface
C#CC# / help
3y ago
❔ Ctor DI vs IServiceProvider.GetService
C#CC# / help
4y ago