Core.Option<'T> 联合 (F#)

指定可选值的类型,可能在有或没有值的时候用到。

命名空间/模块路径: Microsoft.FSharp.Core

程序集:FSharp.Core(在 FSharp.Core.dll 中)

[<DefaultAugmentation(false)>]
[<StructuralEquality>]
[<StructuralComparison>]
type Option<'T> =
| None
| Some of 'T
 with
  interface IStructuralEquatable
  interface IComparable
  interface IComparable
  interface IStructuralComparable
  static member Some : 'T -> 'T option
  member this.IsNone :  bool
  member this.IsSome :  bool
  static member None :  'T option
  member this.Value :  'T
 end

备注

使用构造函数 Some 和 None 可创建此类型的值。 使用 Option 模块中的值可操作此类型的值,或直接对这些值进行模式匹配。 None 值显示为其他 .NET Framework 语言的值 null。 因为 null 用作值表示形式,因此此类型的实例方法显示为其他 .NET Framework 语言的静态方法,

有关选项的概述,请参见选项 (F#)

此类型在编译的程序集中名为 FSharpOption。 如果从 F# 以外的 .NET 语言中访问类型,或通过反射访问类型,请使用此名称。

实例成员

成员

说明

IsNone

如果该选项为 None 值,则返回 true。

IsSome

如果该选项为 Some 值,则返回 true。

获取 Some 选项的值。 如果该选项为 None,则引发 NullReferenceException

静态成员

成员

说明

创建一个为 None 值的选项值。

Some

创建一个为 Some 值的选项值。

联合用例

Case

说明

None

说明此处没有值。

Some of 'T

当没有值时包含该值。

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本信息

F# 运行时

受以下版本支持:2.0、4.0

Silverlight

受以下版本支持:3

请参见

参考

Microsoft.FSharp.Core 命名空间 (F#)