Boolean Struct

Definition

Represents a Boolean (true or false) value.

[Serializable]
[ComVisible(true)]
public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>

Inherited Members

System.Object

Fields

FalseString

Represents the Boolean value false as a string. This field is read-only.

public static readonly string FalseString
See Also

TrueString

Represents the Boolean value true as a string. This field is read-only.

public static readonly string TrueString
See Also

Methods

CompareTo(Boolean)

Compares this instance to a specified Boolean object and returns an integer that indicates their relationship to one another.

public int CompareTo(bool value)
Parameters
value
Boolean

A Boolean object to compare to this instance.

Returns

A signed integer that indicates the relative values of this instance and value.

Return Value

Condition

Less than zero

This instance is false and value is true.

Zero

This instance and value are equal (either both are true or both are false).

Greater than zero

This instance is true and value is false.

See Also

Equals(Boolean)

Returns a value indicating whether this instance is equal to a specified Boolean object.

public bool Equals(bool obj)
Parameters
obj
Boolean

A Boolean value to compare to this instance.

Returns

true if obj has the same value as this instance; otherwise, false.

See Also

Equals(Object)

Returns a value indicating whether this instance is equal to a specified object.

public override bool Equals(object obj)
Parameters
obj
Object

An object to compare to this instance.

Returns

true if obj is a Boolean and has the same value as this instance; otherwise, false.

Overrides
See Also

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()
Returns

A hash code for the current Boolean.

Overrides

Parse(String)

Converts the specified string representation of a logical value to its Boolean equivalent.

public static bool Parse(string value)
Parameters
value
String

A string containing the value to convert.

Returns

true if value is equivalent to TrueString; false if value is equivalent to FalseString.

Exceptions

value is null.

value is not equivalent to TrueString or FalseString.

See Also

ToString()

Converts the value of this instance to its equivalent string representation (either "True" or "False").

public override string ToString()
Returns

"True" (the value of the TrueString property) if the value of this instance is true, or "False" (the value of the FalseString property) if the value of this instance is false.

Overrides

TryParse(String, out Boolean)

Tries to convert the specified string representation of a logical value to its Boolean equivalent. A return value indicates whether the conversion succeeded or failed.

public static bool TryParse(string value, out bool result)
Parameters
value
String

A string containing the value to convert.

result
Boolean

When this method returns, if the conversion succeeded, contains true if value is equal to TrueString or false if value is equal to FalseString. If the conversion failed, contains false. The conversion fails if value is null or is not equal to the value of either the TrueString or FalseString field.

Returns

true if value was converted successfully; otherwise, false.

See Also

Explicit Interface Implementations

IComparable.CompareTo(Object)

int IComparable.CompareTo(object obj)
Parameters
obj
Object
Returns

IConvertible.GetTypeCode()

TypeCode IConvertible.GetTypeCode()
Returns

IConvertible.ToBoolean(IFormatProvider)

For a description of this member, see ToBoolean(IFormatProvider).

bool IConvertible.ToBoolean(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

true or false.

IConvertible.ToByte(IFormatProvider)

For a description of this member, see ToByte(IFormatProvider).

byte IConvertible.ToByte(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if the value of this instance is true; otherwise, 0.

IConvertible.ToChar(IFormatProvider)

This conversion is not supported. Attempting to use this method throws an InvalidCastException.

char IConvertible.ToChar(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

This conversion is not supported. No value is returned.

Exceptions

You attempt to convert a Boolean value to a Char value. This conversion is not supported.

IConvertible.ToDateTime(IFormatProvider)

This conversion is not supported. Attempting to use this method throws an InvalidCastException.

DateTime IConvertible.ToDateTime(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

This conversion is not supported. No value is returned.

Exceptions

You attempt to convert a Boolean value to a DateTime value. This conversion is not supported.

IConvertible.ToDecimal(IFormatProvider)

For a description of this member, see ToDecimal(IFormatProvider)..

decimal IConvertible.ToDecimal(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToDouble(IFormatProvider)

For a description of this member, see ToDouble(IFormatProvider)..

double IConvertible.ToDouble(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToInt16(IFormatProvider)

For a description of this member, see ToInt16(IFormatProvider).

short IConvertible.ToInt16(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToInt32(IFormatProvider)

For a description of this member, see ToInt32(IFormatProvider).

int IConvertible.ToInt32(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToInt64(IFormatProvider)

For a description of this member, see ToInt64(IFormatProvider).

long IConvertible.ToInt64(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToSByte(IFormatProvider)

For a description of this member, see ToSByte(IFormatProvider).

sbyte IConvertible.ToSByte(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToSingle(IFormatProvider)

For a description of this member, see ToSingle(IFormatProvider)..

float IConvertible.ToSingle(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

IConvertible.ToString(IFormatProvider)

string IConvertible.ToString(IFormatProvider provider)
Parameters
provider
IFormatProvider
Returns

IConvertible.ToType(Type, IFormatProvider)

For a description of this member, see ToType(Type, IFormatProvider).

object IConvertible.ToType(Type type, IFormatProvider provider)
Parameters
type
Type

The desired type.

provider
IFormatProvider

An IFormatProvider implementation that supplies culture-specific information about the format of the returned value.

Returns

An object of the specified type, with a value that is equivalent to the value of this Boolean object.

Exceptions

type is null.

The requested type conversion is not supported.

IConvertible.ToUInt16(IFormatProvider)

For a description of this member, see ToUInt16(IFormatProvider).

ushort IConvertible.ToUInt16(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

See Also

IConvertible.ToUInt32(IFormatProvider)

For a description of this member, see ToUInt32(IFormatProvider).

uint IConvertible.ToUInt32(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

See Also

IConvertible.ToUInt64(IFormatProvider)

For a description of this member, see ToUInt64(IFormatProvider).

ulong IConvertible.ToUInt64(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

1 if this instance is true; otherwise, 0.

See Also