Thursday, December 21, 2017

decimal.TryParse in C#


decimal.TryParse method is used to convert given string to its decimal number same like decimal.Parse but the main difference is that it does not throw exception even if the input is not in correct format or is null.

Syntax:
decimal.TryParse(string str, out returnValue);

str is Input string.
returnValue: decimal number equivalent to “str”.

If the conversion is successful, the given string in converted into decimal number otherwise 0 is returned to the out parameter.



This function returns true for successful conversion and false if conversion is failed. Every time there will be one of two results either 0 if failed or value if successful. There will not be any type of exception thrown by this function even if the input string is:

a)   Null                                      :        NO ArgumentNullException
b)   Not is correct format            :        NO FormatException
c)    Out of range                         :        NO OverflowException


Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: