Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“带”的多约束方法;新";_C#_Generics_Generic Constraints - Fatal编程技术网

C# C“带”的多约束方法;新";

C# C“带”的多约束方法;新";,c#,generics,generic-constraints,C#,Generics,Generic Constraints,我试图定义一个具有多个约束的方法,其中T类型可以用作构造函数: private void GetData<T, OType>(string url, string token1, string token2, Action<T, SqlConnection, SqlTransaction> bulkInsert, string user = null, string pwd = null) where T : JsonElements<OType>,

我试图定义一个具有多个约束的方法,其中
T
类型可以用作构造函数:

private void GetData<T, OType>(string url, string token1, string token2, Action<T, SqlConnection, SqlTransaction> bulkInsert, string user = null, string pwd = null) 
    where T : JsonElements<OType>, new
    where OType : class 
{
    var thing = T();
private void GetData(字符串url、字符串token1、字符串token2、操作bulkInsert、字符串user=null、字符串pwd=null)
其中T:jsonements,new
其中OType:class
{
var-thing=T();
我在
new
部分遇到了一个错误

)期望

正确的语法是什么?

您必须使用
new()
,而不仅仅是
new
。这是无参数构造函数的直观线索

另外,在分配
对象时,必须使用
new T()