TryParse Method
Definition
TryParse<T>(string, out T)
Converts the specified input to an object of T. A return value indicates whether the conversion succeeded.
bool TryParse<T>(string input, out T result)
Parameters
inputstringThe string to convert.
resultTWhen this method returns, contains the object of
Tequivalent toinput, if the conversion succeeded, ordefaultif the conversion failed.
Returns
- bool
trueifinputwas converted successfully; otherwise,false.
Type Parameters
TThe type of the object to return.
TryParse(string, Type, out object)
Converts the specified input to an object of targetType. A return value indicates whether the conversion succeeded.
bool TryParse(string input, Type targetType, out object result)
Parameters
inputstringThe string to convert.
targetTypeTypeThe type of the object to return.
resultobjectWhen this method returns, contains the object of
targetTypeequivalent toinput, if the conversion succeeded, ordefaultif the conversion failed.
Returns
- bool
trueifinputwas converted successfully; otherwise,false.