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

260
Visualizações
What does the "default" generic constraint do?

The following code compiles, but it seems that Microsoft's docs don't mention this particular constraint type at all.

class TestGenericsBase<T1>
{
    public virtual void Method1<T>(T arg)
    {
    }
}

class TestGenerics : TestGenericsBase<object>
{
    public override void Method1<T>(T arg)
        where T : default // what does this do?
    {
    }
}

Any idea what does it do? The only clue I have so far is that it only works on methods.

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

0

This default constraint can be found in C#9 design proposal for nullable reference types. It was added to disambiguate between class in struct constraints in overriden or explicitly implemented methods for nullable generic parameters T?.

More details also can be found in the Unconstrained type parameter annotations proposal

To allow annotations for type parameters that are not constrained to reference types or value types, C#9 allows a new where T : default constraint.

These constraints and annotations are working within nullable contexts

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