Udostępnij za pośrednictwem


List.sum<^T> — Funkcja (F#)

Zwraca sumę elementów na liście.

Ścieżka obszaru nazw/modułu: Microsoft.FSharp.Collections.List

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

// Signature:
List.sum : ^T list -> ^T (requires ^T with static member (+) and ^T with static member Zero)

// Usage:
List.sum list

Parametry

  • list
    Type: ^Tlist

    Lista wejściowego.

Wartość zwracana

Wynikowa suma.

Uwagi

Ta funkcja o nazwie Sum w skompilowane zestawy.Jeżeli języka, niż F# lub przez odbicie, uzyskują dostęp do funkcji, należy użyć tej nazwy.

Przykład

Poniższy przykład kodu ilustruje użycie List.sum, List.sumBy, i List.average.

// Compute the sum of the first 10 integers by using List.sum. 
let sum1 = List.sum [1 .. 10]

// Compute the sum of the squares of the elements of a list by using List.sumBy. 
let sum2 = List.sumBy (fun elem -> elem*elem) [1 .. 10]

// Compute the average of the elements of a list by using List.average. 
let avg1 = List.average [0.0; 1.0; 1.0; 2.0]

printfn "%f" avg1

Dane wyjściowe

  

Platformy

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

Informacje o wersji

F# Core wersji biblioteki

Obsługiwane: 2.0, 4.0, przenośne

Zobacz też

Informacje

Collections.List — Moduł (F#)

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