共用方式為


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

將指定的函式套用至集合的每一個項目。傳遞給這個函式的整數表示項目的索引。

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

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

// Signature:
Seq.iteri : (int -> 'T -> unit) -> seq<'T> -> unit

// Usage:
Seq.iteri action source

參數

  • action
    型別:int -> 'T -> unit

    套用至序列之每個項目的函式,也可以存取目前索引。

  • source
    型別:seq<'T>

    輸入序列。

例外狀況

例外狀況

條件

ArgumentNullException

當輸入序列為 null 時擲回。

備註

這個函式在 .NET 組件中名為 IterateIndexed。如果是透過 F# 以外的 .NET 語言存取成員,或透過反映存取成員,請使用這個名稱。

範例

下列程式碼示範如何使用 Seq.iteri,並將其行為與相關函式進行比較。

let seq1 = [1; 2; 3]
let seq2 = [4; 5; 6]
Seq.iter (fun x -> printfn "Seq.iter: element is %d" x) seq1
Seq.iteri(fun i x -> printfn "Seq.iteri: element %d is %d" i x) seq1
Seq.iter2 (fun x y -> printfn "Seq.iter2: elements are %d %d" x y) seq1 seq2

Output

  

平台

Windows 8 中, Windows 7, Windows Server 2012 上, Windows Server 2008 R2

版本資訊

F# 核心程式庫版本

支援版本:2.0, 4.0,可攜式執行檔 (PE)。

請參閱

參考

Collections.Seq 模組 (F#)

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