Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constrains are not allowed at non-generic declaration

 private Result Execute(
     out T returnValue, 
     string storedProcedureName, 
     Hashtable parameters, 
     ExecuteType executeType) 
   where T : class

What does the following error mean, and how can I fix it?

Error at where :Constrains are not allowed at non-generic declaration

like image 403
Arpan Shah Avatar asked Dec 01 '22 06:12

Arpan Shah


2 Answers

private Result Execute<T>(
                           out T returnValue, 
                           string storedProcedureName, 
                           Hashtable parameters, 
                           ExecuteType executeType
                         ) where T : class

Note the required <T> after Execute.

like image 132
dlev Avatar answered Dec 05 '22 15:12

dlev


Yes It works with extension methods also.

class Class1<T> where T:class
{
    public void MethodA()
    {
        Console.WriteLine("Method A");
    }
}

static class ExtenstionTest
{
    public static void MethodA<T>(this Class1<T> A1, int a) where T : class
    {
        Console.WriteLine("Extension Method A" + a);
    }
}
like image 41
Vinita Avatar answered Dec 05 '22 15:12

Vinita