Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:28:35+00:00 2026-05-11T07:28:35+00:00

Why is the following forbidden? Nullable<Nullable<int>> whereas struct MyNullable <T> { } MyNullable<Nullable<int>> is

  • 0

Why is the following forbidden?

Nullable<Nullable<int>> 

whereas

struct MyNullable <T> {   }  MyNullable<Nullable<int>>  

is NOT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:28:35+00:00Added an answer on May 11, 2026 at 7:28 am

    This is because the struct constraint actually means ‘not nullable’ since Nullable, despite being a struct, is nullable (can accept the value null) the Nullable<int> is not a valid type parameter to the outer Nullable.

    This is made explicit in the constraints documentation

    where T: struct
    The type argument must be a value type. Any value type except Nullable can be specified.
    See Using Nullable Types (C# Programming Guide) for more information.

    If you want the rationale for that you would need the actual language designer’s comments on it which I can’t find. However I would postulate that:

    1. the compiler and platform changes required to achieve Nullable in it’s current form are quite extensive (and were a relatively last minute addition to the 2.0 release).
    2. They have several potentially confusing edge cases.

    Allowing the equivalent of int?? would only confuse that since the language provides no way of distinguishing Nullable<Nullable<null>> and Nullable<null> nor any obvious solution to the following.

    Nullable<Nullable<int>> x = null; Nullable<int> y = null; Console.WriteLine(x == null); // true Console.WriteLine(y == null); // true Console.WriteLine(x == y); // false or a compile time error! 

    Making that return true would be very complex and significant overhead on many operations involving the Nullable type.

    Some types in the CLR are ‘special’, examples are strings and primitives in that the compiler and runtime know a lot about the implementation used by each other. Nullable is special in this way as well. Since it is already special cased in other areas special casing the where T : struct aspect is not such a big deal. The benefit of this is in dealing with structs in generic classes because none of them, apart from Nullable, can be compared against null. This means the jit can safely consider t == null to be false always.

    Where languages are designed to allow two very different concepts to interact you tend to get weird, confusing or down right dangerous edge cases. As an example consider Nullable and the equality operators

    int? x = null; int? y = null; Console.WriteLine(x == y); // true Console.WriteLine(x >= y); // false!      

    By preventing Nullables when using struct generic constraint many nasty (and unclear) edge cases can be avoided.

    As to the exact part of the specification that mandates this from section 25.7 (emphasis mine):

    The value type constraint specifies that a type argument used for the type parameter must be a value type (§25.7.1). Any non-nullable struct type, enum type, or type parameter having the value type constraint satisfies this constraint. A type parameter having the value type constraint shall not also have the constructor-constraint. The System.Nullable type specifies the non-nullable value type constraint for T. Thus, recursively constructed types of the forms T?? and Nullable<Nullable<T>> are prohibited.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 144k
  • Answers 144k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IEditorPart.getEditorInput() returns an IEditorInput representing the editor input. If the… May 12, 2026 at 8:38 am
  • Editorial Team
    Editorial Team added an answer There just isn't an implicit conversion from an enum type… May 12, 2026 at 8:38 am
  • Editorial Team
    Editorial Team added an answer Here's the solution that I came up with but it… May 12, 2026 at 8:37 am

Related Questions

I've noticed that if the path parameter to the CreateFile function targets \Windows\System32\ the
Why is it impossible to have a reference to void? The only thing I
Why is the following C# code not allowed: public abstract class BaseClass { public
Why is the following code crashing in PHP? $normal_array = array(); $array_of_arrayrefs = array(

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.