C# | Boolean.TryParse() Method Last Updated : 20 Apr, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to convert the specified string representation of a logical value to its Boolean equivalent. It returns a value that indicates whether the conversion succeeded or failed. Syntax: public static bool TryParse (string value, out bool result); Parameters: value: It is a string containing the value to convert. result: When this method returns, if the conversion succeeded, contains true if value is equal to TrueString or false if value is equal to FalseString. If the conversion failed, contains false. The conversion fails if the value is null or is not equal to the value of either the TrueString or FalseString field. Return Value: This method returns true if value was converted successfully otherwise it returns false. Below programs illustrate the use of Boolean.TryParse(String, Boolean) Method: Example 1: CSharp // C# program to demonstrate // Boolean.TryParse(String, Boolean) // Method using System; class GFG { // Main Method public static void Main() { // passing different values // to the method to check checkParse("true"); checkParse("false"); checkParse("' true '"); checkParse(" $ "); checkParse("1"); } // Declaring checkparse method public static void checkParse(string value) { // Declaring data type bool result; bool flag; // using the method result = Boolean.TryParse(value, out flag); // Display boolean type result Console.WriteLine("{0} --> {1} ", value, result); } } Output: true --> True false --> True ' true ' --> False $ --> False 1 --> False Example 2: CSHARP // C# program to demonstrate // Boolean.TryParse(String, Boolean) // Method using System; class GFG { // Main Method public static void Main() { // passing different values // to the method to check checkParse("true1"); checkParse(null); checkParse(String.Empty); } // Declaring checkparse method public static void checkParse(string value) { // Declaring data type bool result; bool flag; // using the method result = Boolean.TryParse(value, out flag); // Display boolean type result Console.WriteLine("{0} --> {1} ", value, result); } } Output: true1 --> False --> False --> False Note: The TryParse method is like the Parse method, except the TryParse method does not throw an exception if the conversion fails. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.boolean.tryparse?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Boolean.TryParse() Method R rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp-Boolean-Struct Similar Reads C# | Boolean.Parse() Method This method is used to convert the specified string representation of a logical value to its Boolean equivalent. Syntax: public static bool Parse (string value); Here, the value is the string which contains the value to convert.Return Value: This method returns true if value is equivalent to TrueStr 3 min read C# | Char.TryParse () Method In C#, Char.TryParse() is Char class method which is used to convert the value from given string to its equivalent Unicode character. Its performance is better than Char.Parse() method. Syntax : public static bool TryParse(string str, out char result) Parameter: str: It is System.String type paramet 2 min read C# | Boolean.Equals(Object) Method Boolean.Equals(Object) Method is used to get a value which indicates whether the current instance is equal to a specified object or not. Syntax: public override bool Equals (object obj); Here, it takes an object to compare with the current instance. Return Value: This method returns true true if obj 2 min read C# | Boolean.CompareTo(Object) Method Boolean.CompareTo(Object) Method is used to compare the current instance to a specified object and returns an integer which shows their relationship to one another. Syntax: public int CompareTo (object obj); Here, it takes an object to compare to current instance or null. Return Value: This method r 2 min read C# | Char.Parse(String) Method This method is used to convert the value of the specified string to its equivalent Unicode character. Syntax: public static char Parse (string s); Here, s is a string that contains a single character, or null. Return Value: This method returns a Unicode character equivalent to the sole character in 3 min read Like