C# Generic new() constructor problem
- by LB
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 correct error message is: 'T': cannot provide arguments when creating an instance of a variable
But it does! Any ideas?
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.
}
...
}