Is there a generic constructor with parameter constraint in C#?

As you’ve found, you can’t do this.

As a workaround I normally supply a delegate that can create objects of type T:

public class A {

    public static void Method<T> (T a, Func<float[,], T> creator) {
        //...do something...
    }

}

Leave a Comment