共用方式為


List.iteri2<'T1,'T2> 函式 (F#)

將指定的函式同時套用至兩個集合。 這些集合的大小必須完全相同。 傳遞給這個函式的整數表示項目的索引。

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

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

// Signature:
List.iteri2 : (int -> 'T1 -> 'T2 -> unit) -> 'T1 list -> 'T2 list -> unit

// Usage:
List.iteri2 action list1 list2

參數

  • action
    型別:int -> 'T1 -> 'T2 -> unit

    要套用至輸入清單中的項目配對及其索引的函式。

  • list1
    型別:'T1 list

    第一個輸入清單。

  • list2
    型別:'T2 list

    第二個輸入清單。

例外狀況

例外狀況

條件

ArgumentException

會在輸入清單的長度不同時擲回。

備註

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

範例

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

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

Output

  

平台

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

版本資訊

F# 核心程式庫版本

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

請參閱

參考

Collections.List 模組 (F#)

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