/// <summary> /// Tries to parse the string value into the number. /// If successful, returns true and sets the 'res' parameter to the parsed value. /// False is returned otherwise; no exceptions are thrown. /// </summary> /// <typeparam name="T">The type of the number.</typeparam> /// <param name="calculator">A calculator for the <typeparamref name="T"/> type.</param> /// <param name="value">The value to be parsed into a <typeparamref name="T"/> variable.</param> /// <param name="res">A variable to store the result. Will be null or zero in case of a failure.</param> /// <returns>True if the conversion succeeded, false otherwise.</returns> public static bool tryParse <T>(this ICalc <T> calculator, string value, out T res) { try { res = calculator.parse(value); } catch { res = default(T); return(false); } return(true); }