
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Boolean.CompareTo(Boolean) Method in C#
The Boolean.CompareTo(Boolean) method in C# is used to compare this instance to a specified Boolean object and returns an integer that indicates their relationship to one another.
Syntax
Following is the syntax −
public int CompareTo (bool val);
Above, Val is a Boolean object to compare to the current instance.
Example
Let us now see an example to implement the Boolean.CompareTo(Boolean) method −
using System; public class Demo { public static void Main(){ bool b1, b2; b1 = false; b2 = false; int res = b2.CompareTo(b1); if (res > 0) Console.Write("b1 > b2"); else if (res < 0) Console.Write("b1 < b2"); else Console.Write("b1 = b2"); } }
Output
This will produce the following output −
b1 = b2
- Related Articles
- Boolean.Equals(Boolean) Method in C#
- Convert Java Boolean Primitive to Boolean object
- Create a Boolean object from Boolean value in Java
- Java Program to convert boolean value to Boolean
- Explain non-boolean value coercion to a boolean one in JavaScript?
- Boolean Type in Java
- Boolean Literals in Java
- Boolean Indexing in Pandas
- Boolean Indexing in Python
- Boolean Values in Python
- Boolean Gates in JavaScript
- Python Boolean Operations
- C++ Boolean Matrix
- Java Boolean operators
- Generate Random boolean in Java

Advertisements