开发者

Universal Parse Primitive Type on C#

开发者 https://www.devze.com 2022-12-22 23:20 出处:网络
I have string value and Type of some variable (For example int and \"32\"开发者_C百科 or bool and true). My type is primitive type. Can I parse string to my type in one line?Yes.

I have string value and Type of some variable (For example int and "32"开发者_C百科 or bool and true). My type is primitive type. Can I parse string to my type in one line?


Yes.

Convert.ChangeType(value, type);


object res = Convert.ChangeType("123", myType);
0

精彩评论

暂无评论...
验证码 换一张
取 消