System.Boolean Struct
Namespace: System
Represents a Boolean value (true or false). This is a primitive type.
Summary
Fields
Constants and fields for Boolean values.
Methods
Instance methods available on Boolean values.
Operators
Overloaded operators for Boolean logic.
Fields
Boolean.False
Represents the logical false value.
Boolean.True
Represents the logical true value.
Methods
Boolean.Equals(Object obj)
Determines whether the specified object is equal to the current instance.
Boolean.Equals(Boolean value)
Determines whether the specified Boolean value is equal to the current instance.
Boolean.GetHashCode()
Returns the hash code for the current instance.
Boolean.GetTypeCode()
Returns the underlying type code for the Boolean type.
Boolean.Parse(String value)
Converts the string representation of a number to its equivalent Boolean value.
Boolean.ToString()
Converts the value of the current Boolean object to its equivalent string representation.
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
Boolean.operator &(Boolean left, Boolean right)
Performs a logical AND operation.
Boolean.operator |(Boolean left, Boolean right)
Performs a logical OR operation.
Boolean.operator ^(Boolean left, Boolean right)
Performs a logical XOR operation.
Boolean.operator !(Boolean value)
Performs a logical NOT operation.
Boolean.operator ==(Boolean left, Boolean right)
Compares two Boolean values for equality.
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'");
}
}
}