Friday, December 22, 2017

bool.TryParse in C#

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

bool.TryParse(string str, out returnValue);

str is Input string.
returnValue: Boolean value.

If the conversion is successful, true is returned otherwise false 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 false if failed or true 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
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.