-2

I'm trying to define a method that has multiple constraints where the T type is able to be used as a constructor:

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();

I'm getting an error on the new part though saying

) expected

What's the right syntax for this?

Gargoyle
  • 9,590
  • 16
  • 80
  • 145

1 Answers1

4

You have to use new(), not just new. This is a visual clue to a parameter-less constructor.

Also, you have to use new T() when assigning thing.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445