Skip to content

Nullable-generics interaction doesn't work as expected. #7609

Closed Answered by CyrusNajmabadi
mlavrent asked this question in Q&A
Discussion options

You must be logged in to vote

This is by design. When T is unconstrained (no struct or class constraint) then T? simply means "can have its default value" (not can be null).

If you have the class constraint then it is known to be a reference type, and can be null. Similarly, if you have the struct constraint then T? means Nullable<T> which can also be null.

Are there plans to address this?

No. This has been how generics have worked in .net and c# for 20 years. Far too much code has been written that depends on things working in this exact fashion.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mlavrent
Comment options

@mlavrent
Comment options

@HaloFour
Comment options

Answer selected by CyrusNajmabadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants