Interface defining a constructor signature?

You can’t. It’s occasionally a pain, but you wouldn’t be able to call it using normal techniques anyway.

In a blog post I’ve suggested static interfaces which would only be usable in generic type constraints – but could be really handy, IMO.

One point about if you could define a constructor within an interface, you’d have trouble deriving classes:

public class Foo : IParameterlessConstructor
{
    public Foo() // As per the interface
    {
    }
}

public class Bar : Foo
{
    // Yikes! We now don't have a parameterless constructor...
    public Bar(int x)
    {
    }
}

Leave a Comment