共用方式為


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

傳回序列,以指定的次數最多的項目。

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

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

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

// Usage:
Seq.take count source

參數

  • count
    型別:int

    要接受的項目數目。

  • source
    型別:seq<'T>

    輸入序列。

例外狀況

例外狀況

條件

ArgumentException

當輸入序列為空白時擲回。

ArgumentNullException

當輸入序列為 null 時擲回。

InvalidOperationException

會在計數超出序列中的項目數目時擲回。

傳回值

結果序列。

備註

Seq.truncate 傳回多個項目,如序列包含代替擲回例外狀況。

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

範例

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

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#)