Table of Contents

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

T

Value type.

Implements
Inherited Members

Constructors

Optional(T)

Represents an optional value that may be present or absent.

public Optional(T value)

Parameters

value T

Properties

HasValue

Gets a value indicating whether an actual value is present.

public bool HasValue { get; }

Property Value

bool

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

other IOptional

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(Optional<T>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Optional<T> other)

Parameters

other Optional<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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 None when no value is present.

Operators

operator ==(Optional<T>, IOptional)

public static bool operator ==(Optional<T> left, IOptional right)

Parameters

left Optional<T>
right IOptional

Returns

bool

operator ==(Optional<T>, Optional<T>)

public static bool operator ==(Optional<T> left, Optional<T> right)

Parameters

left Optional<T>
right Optional<T>

Returns

bool

operator !=(Optional<T>, IOptional)

public static bool operator !=(Optional<T> left, IOptional right)

Parameters

left Optional<T>
right IOptional

Returns

bool

operator !=(Optional<T>, Optional<T>)

public static bool operator !=(Optional<T> left, Optional<T> right)

Parameters

left Optional<T>
right Optional<T>

Returns

bool