Struct Optional<T>
- Namespace
- Executables
- Assembly
- executables.dll
Represents an optional value that may be present or absent.
public readonly struct Optional<T> : IOptional, IEquatable<Optional<T>>, IEquatable<IOptional>
Type Parameters
TValue type.
- Implements
-
IEquatable<Optional<T>>
- Inherited Members
Constructors
Optional(T)
Represents an optional value that may be present or absent.
public Optional(T value)
Parameters
valueT
Properties
HasValue
Gets a value indicating whether an actual value is present.
public bool HasValue { get; }
Property Value
None
Gets an empty optional value.
public static Optional<T> None { get; }
Property Value
- Optional<T>
Value
Gets the contained value or throws when no value is present.
public T Value { get; }
Property Value
- T
Exceptions
- InvalidOperationException
Throws when no value is present.
ValueOrDefault
Gets the contained value or default value when no value is present.
public T ValueOrDefault { get; }
Property Value
- T
Methods
Equals(IOptional)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(IOptional other)
Parameters
otherIOptionalAn object to compare with this object.
Returns
Equals(Optional<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Optional<T> other)
Parameters
otherOptional<T>An object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the string representation of the optional value.
public override string ToString()
Returns
- string
The contained value as a string, or
Nonewhen no value is present.
Operators
operator ==(Optional<T>, IOptional)
public static bool operator ==(Optional<T> left, IOptional right)
Parameters
Returns
operator ==(Optional<T>, Optional<T>)
public static bool operator ==(Optional<T> left, Optional<T> right)
Parameters
Returns
operator !=(Optional<T>, IOptional)
public static bool operator !=(Optional<T> left, IOptional right)
Parameters
Returns
operator !=(Optional<T>, Optional<T>)
public static bool operator !=(Optional<T> left, Optional<T> right)