To

public static T To<T>(this IConvertible value)
        {
            try
            {
                return (T) Convert.ChangeType(value, typeof (T));
            }
            catch
            {
                return default(T);
            }
        }
Example:
var age = "28";
var intAge = age.To<int>();
var doubleAge = intAge.To<double>();
var decimalAge = doubleAge.To<decimal>();

Description

converts one type to another

Details

Double click on the code to select all.

 

;