Udostępnij za pośrednictwem


Array.iteri<'T> — Funkcja (F#)

Stosuje daną funkcję do do każdego elementu tablicy.Przekazana do funkcji liczba całkowita wskazuje indeks elementu.

Przestrzeń nazw/Ścieżka modułu: Microsoft.FSharp.Collections.Array

Zestaw:: FSharp.Core (w FSharp.Core.dll)

// Signature:
Array.iteri : (int -> 'T -> unit) -> 'T [] -> unit

// Usage:
Array.iteri action array

Parametry

  • action
    Wpisz: int -> 'T -> jednostka

    Funkcja do stosowania do każdego indeksu i elementu.

  • array
    Typ: 'T[]

    Tablica wejściowa.

Uwagi

Ta funkcja nosi nazwę IterateIndexed w skompilowanych zestawach.Jeśli uzyskujesz dostęp do funkcji języka .NET, innego niż F# lub przez odbicie, użyć tej nazwy.

Przykład

Następujące przykłady kodu przedstawiają różnice między Array.iter, Array.iter2, Array.iteri, and Array.iteri2.

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

Dane wyjściowe

  

Platformy

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

Informacje o wersji

Wersje podstawowe biblioteki języka F#

Obsługiwane przez: 2.0, 4.0, przenośne

Zobacz też

Informacje

Collections.Array — Moduł (F#)

Microsoft.FSharp.Collections — Przestrzeń nazw (F#)