Optional struct¶
Attributes: [DebuggerDisplay("HasValue = {HasValue}, Value = {_value}")]
Defined in
Namespace: ReactiveUI.Primitives
Assembly: ReactiveUI.Primitives.Core.dll
Full name: ReactiveUI.Primitives.Optional<T>
Modifiers: public sealed
Summary¶
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¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [Optional](# struct. |
Properties¶
| Name | Summary |
|---|---|
| static Empty | Gets an empty instance of the [Optional](# type that contains no value. |
| static None | Gets an empty optional value. |
| HasValue | Gets a value indicating whether the current instance has a valid value assigned. |
| Value | Gets the value contained in the optional object. |
Methods¶
| Name | Summary |
|---|---|
| static Some | Creates an optional value containing a value. |
| ToString | |
| GetHashCode | |
| Equals |
Operators¶
| Name | Summary |
|---|---|
| static op_Inequality | |
| static op_Equality |