Using a variable type’s new() method

So, I wanna create a class with capabilities like List<> (but unlike List<> in function).

I've created the class as follows:

 public class Test<Type> where Type : SpecificType, new() {} 

So Type (Variable name of the SpecificType passed to Test) should inherit from SpecificType. The ", new()" part allows me to construct the SpecificType, but not to use the SpecificType's constructors. How can I access the SpecificType's constructors? If the question is unclear, please ask me to clarify, as this is a topic I am new to, and thus I am not sure on all the terms etc 🙂

by PineappleMechanic via /r/csharp

Leave a Reply