System.Boolean Struct

Namespace: System

Represents a Boolean value (true or false). This is a primitive type.

Summary

Struct
Fields Constants and fields for Boolean values.
Struct
Methods Instance methods available on Boolean values.
Struct
Operators Overloaded operators for Boolean logic.

Fields

Field
Boolean.False Represents the logical false value.
Field
Boolean.True Represents the logical true value.

Methods

Method
Boolean.Equals(Object obj) Determines whether the specified object is equal to the current instance.
Method
Boolean.Equals(Boolean value) Determines whether the specified Boolean value is equal to the current instance.
Method
Boolean.GetHashCode() Returns the hash code for the current instance.
Method
Boolean.GetTypeCode() Returns the underlying type code for the Boolean type.
Method
Boolean.Parse(String value) Converts the string representation of a number to its equivalent Boolean value.
Method
Boolean.ToString() Converts the value of the current Boolean object to its equivalent string representation.
Method
Boolean.TryParse(String value, out Boolean result) Converts the string representation of a number to its equivalent Boolean value. A return value indicates whether the conversion succeeded.

Operators

Operator
Boolean.operator &(Boolean left, Boolean right) Performs a logical AND operation.
Operator
Boolean.operator |(Boolean left, Boolean right) Performs a logical OR operation.
Operator
Boolean.operator ^(Boolean left, Boolean right) Performs a logical XOR operation.
Operator
Boolean.operator !(Boolean value) Performs a logical NOT operation.
Operator
Boolean.operator ==(Boolean left, Boolean right) Compares two Boolean values for equality.
Operator
Boolean.operator !=(Boolean left, Boolean right) Compares two Boolean values for inequality.

Examples

Basic Usage

using System;

public class Example
{
    public static void Main()
    {
        Boolean isComplete = true;
        Boolean hasErrors = false;

        Console.WriteLine($"Is complete: {isComplete}");
        Console.WriteLine($"Has errors: {hasErrors}");

        if (isComplete && !hasErrors)
        {
            Console.WriteLine("Operation successful!");
        }
    }
}

Parsing

using System;

public class Example
{
    public static void Main()
    {
        Boolean result1;
        if (Boolean.TryParse("True", out result1))
        {
            Console.WriteLine($"Parsed 'True': {result1}");
        }

        Boolean result2 = Boolean.Parse("False");
        Console.WriteLine($"Parsed 'False': {result2}");

        Boolean result3;
        if (!Boolean.TryParse("Invalid", out result3))
        {
            Console.WriteLine("Failed to parse 'Invalid'");
        }
    }
}