Saturday, March 21, 2015

Convert.ChangeType in C#

It looks like this:

Type type = typeof(Int32);
string thirteen = "13";
int integer = (Int32)Convert.ChangeType(thirteen, type, CultureInfo.InvariantCulture);

 
 

...and, yes, you have to have that casting in the last line of code.

No comments:

Post a Comment