Skip to content

Optional struct

Defined in

Namespace: ReactiveUI.Extensions.Async Assembly: ReactiveUI.Extensions.dll Full name: ReactiveUI.Extensions.Async.Optional<T> Modifiers: public sealed

Summary

View source

        Represents an optional value that may or may not be present.
        

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Class hierarchy
classDiagram
class Optional~T~
class IEquatable~Optional~T~~ {
    <>
}
IEquatable~Optional~T~~ <|.. Optional~T~

Implements: IEquatable>

Remarks

Use this struct to indicate the presence or absence of a value without resorting to null references. When an instance has a value, the HasValue property is true and the Value property returns the contained value. If no value is present, HasValue is false and accessing Value throws an exception. This pattern is useful for APIs that need to distinguish between an explicit 'no value' state and a default value.

Constructors

NameSummary
.ctorInitializes a new instance of the [Optional](# struct.

Properties

NameSummary
static EmptyGets an empty instance of the [Optional](# type that contains no value.
HasValueGets a value indicating whether the current instance has a valid value assigned.
ValueGets the value contained in the optional object.

Methods

NameSummary
ToString
GetHashCode
Equals

Operators

NameSummary
static op_Inequality
static op_Equality