How to use typeof or GetType() as Generic's Template?

前端 未结 4 1126
眼角桃花
眼角桃花 2020-12-14 06:57

If it\'s harder to explain using words, let\'s look at an example I have a generic function like this

void FunctionA() where T : Form, new()
{
}
         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 07:51

    A few years late and from a msdn blog, but this might help:

    Type t = typeof(Customer);  
    IList list = (IList)Activator.CreateInstance((typeof(List<>).MakeGenericType(t)));  
    Console.WriteLine(list.GetType().FullName); 
    

提交回复
热议问题