共用方式為


Lazy.Create<'T> 擴充方法 (F#)

更新:2010 年 5 月

建立延遲計算,用於強制評估所指定函式的結果。

命名空間/模組路徑: Microsoft.FSharp.Control.LazyExtensions

組件:FSharp.Core (在 FSharp.Core.dll 中)

// Signature:
type System.Lazy with
  member static Create : Lazy<'T>

// Usage:
lazy.Create (creator)

參數

  • creator
    型別:unit -> 'T

    需要時用來提供值的函式。

傳回值

所建立的 Lazy 物件。

範例

下列程式碼說明如何使用 Create

let lazyValue n = Lazy.Create (fun () ->
    let rec factorial n =
        match n with
        | 0 | 1 -> 1
        | n -> n * factorial (n - 1)
    factorial n)
let lazyVal = lazyValue 10
printfn "%d" (lazyVal.Force())

輸出是 10 的階乘。

  

平台

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

Silverlight

支援版本:3

請參閱

參考

Control.LazyExtensions 模組 (F#)

Lazy<T>

延遲運算 (F#)

變更記錄

日期

History

原因

2010 年 5 月

加入程式碼範例。

資訊加強。