我想创建一个通用函数,签名类似于:
因此,我创建了一些
void funcName<T>()
,其中T
需要是我想要的某个特定接口的实现。如何进行这样的检查?如何将实现特定接口的类类型传递给通用函数?因此,我创建了一些
public interface IofMine {}
并尝试创建一个函数public static void funcName<T>() where T : IofMine { var a = new T}
,但遗憾的是我得到了以下错误:
我该怎么做才能让我的函数接收的类类型不仅符合我所需的接口,而且还具有构造函数?Error: Cannot create an instance of the variable type 'T' because it does not have the new() constraint