Wednesday, April 4, 2012

c# - String to Generic [Type conversion]

public static T To(this string text)
{
return (T)Convert.ChangeType(text, typeof(T));
}

// sample usage
int val = "124".To();
double dbl = "124.5".To();

No comments:

Post a Comment