I'm trying to create a new object of type T via its constructor when adding to the list.
I'm getting a compile error: The error message is:
'T': cannot provide arguments when creating an instance of a variable
But my classes do have a constructor argument! How can I make this work?
public static string GetAllItems<T>(...) where T : new()
{
...
List<T> tabListItems = new List<T>();
foreach (ListItem listItem in listCollection)
{
tabListItems.Add(new T(listItem)); // error here.
}
...
}
I found that I was getting an error "cannot provide arguments when creating an instance of type parameter T" so I needed to do this: