Optional<T> Structure
An optional typed value.
Definition
Namespace: Avalonia.Data
Assembly: Avalonia.Base (in Avalonia.Base.dll)
- C#
- VB
- F#
public readonly struct Optional<T> : IEquatable<Optional<T>>
Public Structure Optional(Of T)
Implements IEquatable(Of Optional(Of T))
[<SealedAttribute>]
type Optional<'T> =
struct
inherit ValueType
interface IEquatable<Optional<'T>>
end
Inheritance | Object → ValueType → Optional(T) |
Implements | IEquatable(Optional(T)) |
Type Parameters
- The value type.
Remarks
This struct is similar to Nullable(T) except it also accepts reference types: note that null is a valid value for reference types. It is also similar to BindingValue(T) but has only two states: "value present" and "value missing". To create a new optional value you can: - For a simple value, call the Optional(T) constructor or use an implicit conversion from T - For an missing value, use Empty or simply default
Constructors
Optional(T)(T) | Initializes a new instance of the Optional(T) struct with value. |
Properties
Empty | Returns an Optional(T) without a value. |
HasValue | Gets a value indicating whether a value is present. |
Value | Gets the value. |
Methods
Equals(Object) | Indicates whether this instance and a specified object are equal. (Overrides ValueType.Equals(Object)) |
Equals(Optional(T)) | Indicates whether the current object is equal to another object of the same type. |
GetHashCode() | Returns the hash code for this instance. (Overrides ValueType.GetHashCode()) |
GetType() | Gets the Type of the current instance. (Inherited from Object) |
GetValueOrDefault() | Gets the value if present, otherwise the default value. |
GetValueOrDefault(T) | Gets the value if present, otherwise a default value. |
GetValueOrDefault(TResult)() | Gets the value if present, otherwise the default value. |
GetValueOrDefault(TResult)(TResult) | Gets the value if present, otherwise a default value. |
ToObject() | Casts the value (if any) to an Object. |
ToString() | Returns the fully qualified type name of this instance. (Overrides ValueType.ToString()) |
Operators
Equality(Optional(T), Optional(T)) | Compares two Optional(T)s for equality. |
Implicit(T to Optional(T)) | Creates an Optional(T) from an instance of the underlying value type. |
Inequality(Optional(T), Optional(T)) | Compares two Optional(T)s for inequality. |