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

262
Visualizações
Func<...> args have "unnamed" parameters. Is there a way to name them?

Is there a way to named parameters of a generic Func<...> to have support of intellisense?

Example:

Func<int, int, int> f1 = new Func<int, int, int>(
    (a, b) => { return a + b }
);

f1(2, 3);

enter image description here

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

0

No. You can define your own delegate/interface, though.

public delegate int DoTheThing(int a, int b);

or

public interface IThingDoer {
    int DoTheThing(int a, int b);
}
over 4 years ago · Santiago Trujillo Relatório

0

You can't do this with Func<...> since it is already has names for the type parameters (it's just a normal generic type).

You could define a delegate instead (which has to be defined at class level - you can't define it within a method or as a method parameter):

public delegate int MyFunc(int a, int b);

Then you just use it like:

public static int MyMethod(MyFunc myfunc)
{
    return myfunc(1, 2);
}

public static int MyOtherMethod()
{
    return MyMethod((a, b) => a + b);
}

One somewhat grungy workaround could be to use a tuple for the arguments:

public static int MyMethod(Func<(int a, int b), int> myFunc)
{
    return myFunc((1, 2));
}

public static int MyOtherMethod()
{
    return MyMethod(tuple => tuple.a + tuple.b);
}

Then intellisense will tell you the names of the tuple members. I wouldn't do this though - I'm just mentioning it for completeness.

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