How to initialize generic parameter type T?

前端 未结 5 2045
甜味超标
甜味超标 2021-02-05 04:19

Simple question:
If you have a string x, to initialize it you simple do one of the following:

string x = String.Empty;  

or

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 05:00

    If you really need an instance of T and not a default null value for reference types, use:

    Activator.CreateInstance()
    

提交回复
热议问题