C# | Boolean.CompareTo(Boolean) Method Last Updated : 06 Jan, 2022 Comments Improve Suggest changes Like Article Like Report Boolean.CompareTo(Boolean) Method is used to compare the current instance to a specified Boolean object and returns an indication of their relative values. Syntax: public int CompareTo (bool value); Here, the value is a Boolean object to compare to the current instance. Return Value: This method returns a 32-bit signed integer that indicates the relative order of this instance and value. Less than zero: If this instance is false and value is true.Zero: If this instance and value are equal (either both are true or both are false).Greater than zero: If this instance is true and value is false. Example: C# // C# program to demonstrate // Boolean.CompareTo(Boolean) // Method using System; class GFG { // Main Method public static void Main() { // Declaring val1 and val2 bool val1, val2; // initializing the val1, // and val2 val1 = true; val2 = false; // using CompareTo method int i = val2.CompareTo(val1); // checking the condition if (i > 0) Console.Write("val2 is greater than val1"); else if (i < 0) Console.Write("val2 is less than val1"); else Console.Write("val1 is equal to val1"); } } Output: val2 is less than val1 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.boolean.compareto?view=netframework-4.8#System_Boolean_CompareTo_System_Boolean_ Comment More infoAdvertise with us Next Article C# | Boolean.CompareTo(Boolean) Method K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp Boolean Struct Similar Reads C# | Boolean.Equals(Boolean) Method This method is used to return a value indicating whether this instance is equal to a specified Boolean object.Syntax: public bool Equals (bool obj); Here, obj is a boolean value to compare to this instance.Return Value: This method returns true if obj has the same value as this instance otherwise it 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# | Byte.CompareTo(Byte) Method This method is used to compare this instance to a specified 8-bit unsigned integer and returns an indication of their relative values.Syntax: public int CompareTo (byte value); Here, the value is an 8-bit unsigned integer to compare.Return Value: This method returns a signed integer that indicates t 2 min read C# | Char.CompareTo() Method In C#, Char.CompareTo() is a System.Char struct method which is used to compare this instance of a specified object or value type and check whether the given instance is precedes, follow, or appears in the same position in the sort order as the specified object or value type. This method can be over 3 min read C# | Byte.CompareTo(Object) Method This method is used to compare the current instance to a specified object and returns a sign of their relative values. Regardless of value, any instance of Byte will be considered greater than null. Syntax: public int CompareTo (object value); Here, it takes an object to compare, or null. Return Val 2 min read Like