How do i use Activator.CreateInstance with strings?

前端 未结 5 1963
礼貌的吻别
礼貌的吻别 2021-02-05 01:48

In my reflection code i hit a problem with my generic section of code. Specifically when i use a string.

var oVal = (object)\"Test\";
var oType = oVal.GetType();         


        
5条回答
  •  独厮守ぢ
    2021-02-05 02:14

    String actually has no constructor that takes a string as input. There is a constructor that takes a char array so this should work:

    var sz = Activator.CreateInstance ("".GetType (), "Test".ToCharArray ());
    

提交回复
热议问题