Compartilhar via


Função Array.sortInPlaceWith<'T> (F#)

Classifica os elementos de uma matriz transformando a matriz no lugar, usando a função de comparação como determinada ordem.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (em FSharp.Core.dll)

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

// Usage:
Array.sortInPlaceWith comparer array

Parâmetros

  • comparer
    Tipo: 'T -> 'T ->int

    A função para comparar pares de elementos da matriz.

  • array
    Tipo: 'T[]

    A matriz de entrada.

Comentários

Essa função é chamada SortInPlaceWith em assemblies compilados. Se acessar a função de um idioma diferente F#, ou com a reflexão, usa esse nome.

Exemplo

O exemplo de código a seguir mostra como usar Array.sortInPlaceWith.

open System

let array1 = [| "<>"; "&"; "&&"; "&&&"; "<"; ">"; "|"; "||"; "|||" |]
printfn "Before sorting: "
array1 |> printfn "%A" 
let sortFunction (string1:string) (string2:string) =
    if (string1.Length > string2.Length) then
       1
    else if (string1.Length < string2.Length) then
       -1
    else
        String.Compare(string1, string2)
Array.sortInPlaceWith sortFunction array1
printfn "After sorting: "
array1 |> printfn "%A"

Saída

  

Plataformas

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

Informações de Versão

Versões da biblioteca principal de F#

Suportado em: 2,0, 4,0, portáteis

Consulte também

Referência

Módulo Collections.Array (F#)

Namespace Microsoft.FSharp.Collections (F#)