共用方式為


Seq.truncate<'T> 函式 (F#)

傳回序列,列舉這個序列時最多會傳回 N 個項目。

命名空間/模組路徑: Microsoft.FSharp.Collections.Seq

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

// Signature:
Seq.truncate : int -> seq<'T> -> seq<'T>

// Usage:
Seq.truncate count source

參數

  • count
    型別:int

    要列舉的最大項目數。

  • source
    型別:seq<'T>

    輸入序列。

例外狀況

例外狀況

條件

ArgumentNullException

當輸入序列為 null 時擲回。

傳回值

結果序列。

備註

這個函式是名為 Truncate中 已編譯的組件。 如果從一個語言,F # 以外,或透過反映存取函式使用這個名稱。

範例

下列範例示範使用 Seq.truncate對比與行為和 Seq.take

let mySeq = seq { for i in 1 .. 10 -> i*i }
let truncatedSeq = Seq.truncate 5 mySeq
let takenSeq = Seq.take 5 mySeq

let truncatedSeq2 = Seq.truncate 20 mySeq
let takenSeq2 = Seq.take 20 mySeq

let printSeq seq1 = Seq.iter (printf "%A ") seq1; printfn ""

// Up to this point, the sequences are not evaluated.
// The following code causes the sequences to be evaluated.
truncatedSeq |> printSeq
truncatedSeq2 |> printSeq
takenSeq |> printSeq
// The following line produces a run-time error (in printSeq):
takenSeq2 |> printSeq
  

平台

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

請參閱

參考

Collections.Seq 模組 (F#)

Microsoft.FSharp.Collections 命名空間 (F#)