I have simple code witch works ok:
public class Example
{
private List<SomeClass> _list = new List<SomeClass>();
public void Add(SomeClass _b) {
_list.Add(_b);
}
}
it possible to add SomeClass to _list something like this? (without specifying argument)?
public void Add<T>() where T : SomeClass
{
}
Assuming that
SomeClasshas a default constructor, you can:If
SomeClassdoes not have a default constructor then you won’t be able to writenew T()and you will need to find another way of getting aTobject.