Universal Parse Primitive Type on C#
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);
精彩评论