Skip to content
Discussion options

You must be logged in to vote

This is the expected behavior according to the spec (edited for brevity):

In order of preference, the type of a ?? b is A₀, A, or B, where A is the type of a (provided that a has a type), B is the type of b (provided that b has a type), and A₀ is the underlying type of A if A is a nullable value type, or A otherwise. Specifically, a ?? b is processed as follows:

  • […]
  • If A is a nullable value type and an implicit conversion exists from b to A₀, the result type is A₀. At run-time, a is first evaluated. If a is not null, a is unwrapped to type A₀, and this becomes the result. Otherwise, b is evaluated and converted to type A₀, and this becomes the result.
  • […]

In this case, A is int? and A₀

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@bollhals
Comment options

@svick
Comment options

svick Apr 15, 2022
Collaborator

Answer selected by bollhals
Comment options

You must be logged in to vote
0 replies
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