Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!