Skip to content

Unexpected nullability warning in null-coalescing throw expression #7523

Answered by jnm2
JeroenBos asked this question in Q&A
Discussion options

You must be logged in to vote

This would be a smaller step than going all the way to a temporary variable:

object[] c = (a ?? throw new Exception())!;

It makes sense that it would work this way since the ! is targeting the assignment, whereas in your example the ! is targeting the ??.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@JeroenBos
Comment options

Comment options

You must be logged in to vote
1 reply
@333fred
Comment options

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