Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Passing Delegate to Sort()

In the book "Functional C#" by Enrico Buonanno, on page 16, the following Code was given:

namespace System
{
    public delegate int Comparison<in T>(T x, T y);
}

var list = Enumerable.Range(1, 10).Select(i => i * 3).ToList();
list // => [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
Comparison<int> alphabetically = (l, r)
=> l.ToString().CompareTo(r.ToString());
list.Sort(alphabetically);
list // => [12, 15, 18, 21, 24, 27, 3, 30, 6, 9]

This, however, when executed in the REPL, doesn't yield anything useful.

error CS1503: Argument "1": Konvertierung von "Comparison<int>" in "System.Collections.Generic.IComparer<int>" nicht möglich.

What's going wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Comparison is an existing delegate in .NET so you don't need to declare your own. Just remove this declaration and corresponding List.Sort(Comparison<T>) will be invoked - compare this and this.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda