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...
}
}
More Related Contents:
- Create Generic method constraining T to an Enum
- Why can’t the C# constructor infer type?
- ‘UserControl’ constructor with parameters in C#
- Why does the c# compiler emit Activator.CreateInstance when calling new in with a generic type with a new() constraint?
- Is there a reasonable approach to “default” type parameters in C# Generics?
- Can I have a variable number of generic parameters?
- Is generic constructor in non-generic class supported?
- How to capture value OOPS & Generic [closed]
- Virtual member call in a constructor
- Can’t operator == be applied to generic types in C#?
- C# member variable initialization; best practice?
- Casting List of Derived class to List of base class
- No generic implementation of OrderedDictionary?
- Is it worthwhile to initialize the collection size of a List if it’s size reasonably known?
- Using C# reflection to call a constructor
- Generics – where T is a number? [duplicate]
- Struct constructor: “fields must be fully assigned before control is returned to the caller.”
- A reusable pattern to convert event into task
- Sorting an IList in C#
- How do I create a generic class from a string in C#? [duplicate]
- Why aren’t generic type constraints inheritable/hierarchically enforced
- Parse string to enum type
- Why does this generic constraint compile when it seems to have a circular reference
- Case insensitive access for generic dictionary
- How to define generic type limit to primitive types?
- Calling constructor from other constructor in same class
- Are static members of a generic class tied to the specific instance?
- How to constrain generic type to must have a construtor that takes certain parameters?
- How to write this EF Mock setup code as a reusable Generic Boilerplate?
- .NET Managing Layers Relationships