Search Results for

    Show / Hide Table of Contents

    Struct Option<T>

    Represents a value type that can be absent

    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.ReferenceEquals(Object, Object)
    Namespace: Microsoft.ML.Probabilistic.Collections
    Assembly: Microsoft.ML.Probabilistic.dll
    Syntax
    public struct Option<T>
    Type Parameters
    Name Description
    T
    Remarks

    Unlike Nullable<T> this works with value and reference types.

    Constructors

    Option(T)

    Initializes a new instance of the Option<T> structure. If T is reference type and is null then object without data is created (HasValue will be false).

    Declaration
    [Construction(new string[]{"Value"})]
    public Option(T value)
    Parameters
    Type Name Description
    T value

    Properties

    HasNoValue

    Gets a value indicating whether the current Option<T> object has no valid value of its underlying type.

    Declaration
    public readonly bool HasNoValue { get; }
    Property Value
    Type Description
    Boolean
    Remarks

    This property is redundant but is needed for quoting operation.

    HasValue

    Gets a value indicating whether the current Option<T> object has a valid value of its underlying type.

    Declaration
    public readonly bool HasValue { get; }
    Property Value
    Type Description
    Boolean

    Value

    Gets the value of the current Option<T> object if it has been assigned a valid underlying value.

    Declaration
    public readonly T Value { get; }
    Property Value
    Type Description
    T

    The value of the current Option<T> object if the HasValue property is true. An exception is thrown otherwise.

    Methods

    Empty()

    Creates a news Option<T> object which holds no value.

    Declaration
    [Construction(UseWhen = "HasNoValue")]
    public static Option<T> Empty()
    Returns
    Type Description
    Option<T>

    Equals(Object)

    Declaration
    public override bool Equals(object other)
    Parameters
    Type Name Description
    Object other
    Returns
    Type Description
    Boolean
    Overrides
    ValueType.Equals(Object)

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    ValueType.GetHashCode()

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    ValueType.ToString()

    Operators

    Equality(Option<T>, Option<T>)

    Declaration
    public static bool operator ==(Option<T> a, Option<T> b)
    Parameters
    Type Name Description
    Option<T> a
    Option<T> b
    Returns
    Type Description
    Boolean

    Explicit(Option<T> to T)

    Defines an explicit conversion of a Option<T> instance to its underlying value.

    Declaration
    public static explicit operator T(Option<T> value)
    Parameters
    Type Name Description
    Option<T> value
    Returns
    Type Description
    T

    Implicit(T to Option<T>)

    Creates a new Option<T> object initialized to a specified value.

    Declaration
    public static implicit operator Option<T>(T value)
    Parameters
    Type Name Description
    T value
    Returns
    Type Description
    Option<T>

    Implicit(Option.NoneType to Option<T>)

    Creates a new empty Option<T> object.

    Declaration
    public static implicit operator Option<T>(Option.NoneType none)
    Parameters
    Type Name Description
    Option.NoneType none
    Returns
    Type Description
    Option<T>

    Inequality(Option<T>, Option<T>)

    Declaration
    public static bool operator !=(Option<T> a, Option<T> b)
    Parameters
    Type Name Description
    Option<T> a
    Option<T> b
    Returns
    Type Description
    Boolean
    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.