0

Is there a way to do the following?

Type v = typeof(string);
MyClass<v> myClass = new MyClass<v>();

It would be used in the following context:

interface MyClassInterface
{
  Type GetType();
}

class MyClass<T> : MyClassInterface
{
  Type GetType()
  {
    return typeof(T);
  }
}

....in Main:

List<MyClassInterface> list;


foreach(MyClassInterface class in list)
{
  Type type = class.GetType();
  List<type> list = new List<type>();
}

I do not want to declare it of type "object".

Many thanks. Apologies if this is answered somewhere else. I have no idea this is called... "How to keep your Generic generic?"

Philip Stuyck
  • 7,344
  • 3
  • 28
  • 39
MVM
  • 151
  • 1
  • 5

0 Answers0