W
WT
Hello,
I am building a generic class that needs to instanciate an object of its
template class, something like
public class MyGeneric<T>
{
List<T> myList = new List<T>();
void addToLst(List l)
{
foreach(MyObj ob in l)
{
myList.Add(new T(ob));
}
}
}
new T(ob) being refused, I tried Activator.CreateInstance(T, new
Object[]{l}); but T is not a type.
How to call a constructor for the type T used in the generic ?
Thanks for help.
CS
I am building a generic class that needs to instanciate an object of its
template class, something like
public class MyGeneric<T>
{
List<T> myList = new List<T>();
void addToLst(List l)
{
foreach(MyObj ob in l)
{
myList.Add(new T(ob));
}
}
}
new T(ob) being refused, I tried Activator.CreateInstance(T, new
Object[]{l}); but T is not a type.
How to call a constructor for the type T used in the generic ?
Thanks for help.
CS