How to convert string to any type

后端 未结 3 2006
暗喜
暗喜 2020-12-05 09:25

I want to convert a string to a generic type

I have this:

string inputValue = myTxtBox.Text;    

PropertyInfo propInfo = typeof(MyClass).GetProperty         


        
3条回答
  •  伪装坚强ぢ
    2020-12-05 09:58

    using System.ComponentModel;
    
    TypeConverter typeConverter = TypeDescriptor.GetConverter(propType);
    object propValue = typeConverter.ConvertFromString(inputValue);
    

提交回复
热议问题