Mega Code Archive

 
Categories / C# / Data Types
 

Convert string to bool with exception catch

using System; using System.Collections.Generic; using System.Text; static class Utility {     public static bool ConvertStringToBool(string str, bool defaultValue)     {         bool b_str;         try         {             b_str = System.Convert.ToBoolean(str);         }         catch         {             b_str = defaultValue;         }         return b_str;     } }