System.Boolean Struct
Represents the Boolean value (true or false). This type is a value type that implements the
IComparable
, IConvertible
, and IEquatable<Boolean>
interfaces.
Methods
-
CompareTo
(object obj)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
- obj
- An object to compare with this instance.
-
CompareTo
(bool value)
Compares the current instance with another Boolean value and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other value.
- value
- A Boolean value to compare with this instance.
-
Equals
(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
- obj
- An object to compare with this instance.
true
if obj is a Boolean value that is equal to this instance; otherwise,false
. -
Equals
(bool obj)
Returns a value that indicates whether this instance is equal to a specified Boolean value.
- obj
- A Boolean value to compare with this instance.
true
if obj has the same value as this instance; otherwise,false
. -
GetHashCode
()
Returns the hash code for this instance.Returns: A 32-bit signed integer hash code.
-
GetTypeCode
()
Returns the type code for the
System.Boolean
value type.Returns: The enumerated constant,TypeCode.Boolean
, which specifies the type of the current System.Object. -
Parse
(string value)
Converts the specified string representation of a logical value to its
Boolean
equivalent.- value
- A string that contains the values "True", "true", "False", or "false", or their equivalent numeric representations, 1 or 0.
true
if value is "True" or "1";false
if value is "False" or "0". Throws: ArgumentNullException: value is null. FormatException: value is not a valid Boolean representation. -
Parse
(string value, IFormatProvider provider)
Converts the specified string representation of a logical value to its
Boolean
equivalent by using the specified format provider.- value
- A string that contains the values "True", "true", "False", or "false", or their equivalent numeric representations, 1 or 0.
- provider
- An object that supplies culture-specific formatting information.
true
if value is "True" or "1";false
if value is "False" or "0". Throws: ArgumentNullException: value is null. FormatException: value is not a valid Boolean representation. -
ToString
()
Converts the value of this instance to its equivalent string representation.Returns: The string representation of the value of this instance, which is either "True" or "False".
-
ToString
(IFormatProvider provider)
Converts the value of this instance to its equivalent string representation by using the specified format provider.
- provider
- An object that supplies culture-specific formatting information.
-
TryParse
(string value, out bool result)
Converts the string representation of a logical value to its
Boolean
equivalent. A return value indicates whether the conversion succeeded or failed.- value
- A string that contains the values "True", "true", "False", or "false", or their equivalent numeric representations, 1 or 0.
- result
- [out] When this method returns, if the conversion succeeded, result contains
true
orfalse
. If the conversion failed, result containsfalse
.
true
if the value parameter was converted successfully; otherwise,false
. -
TryParse
(string value, IFormatProvider provider, out bool result)
Converts the string representation of a logical value to its
Boolean
equivalent by using the specified format provider. A return value indicates whether the conversion succeeded or failed.- value
- A string that contains the values "True", "true", "False", or "false", or their equivalent numeric representations, 1 or 0.
- provider
- An object that supplies culture-specific formatting information.
- result
- [out] When this method returns, if the conversion succeeded, result contains
true
orfalse
. If the conversion failed, result containsfalse
.
true
if the value parameter was converted successfully; otherwise,false
.
Fields
-
False
static readonly bool
Represents the value
false
. -
True
static readonly bool
Represents the value
true
.
Operators
-
==
(bool b1, bool b2)
Determines whether two Boolean values are equal.
-
!=
(bool b1, bool b2)
Determines whether two Boolean values are not equal.
-
!
(bool b)
Returns the logical NOT of the Boolean value.
-
&&
(bool b1, bool b2)
Returns the logical AND of two Boolean values.
-
||
(bool b1, bool b2)
Returns the logical OR of two Boolean values.
-
^
(bool b1, bool b2)
Returns the logical exclusive OR (XOR) of two Boolean values.