We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm trying to assign a value to a null-able type via a tertiary assignment where: case true: assign non-nullable case false: assign null
case true: assign non-nullable
case false: assign null
DateTime? assignee; DateTime assignment; var condition = false; assignee = condition ? assignment: null;
This results in the compile error: Cannot convert DateTime to nullable.
I would assume that the compiler would translate this into something like:
DateTime? assignee; DateTime assignment; var condition = false; if(condition) { assignee = assignment; }else{ assignee = null; }
Which compiles fine. Whats actually going on here?
The text was updated successfully, but these errors were encountered:
You can use:
assignee = condition ? assignment : default(DateTime?)
Sorry, something went wrong.
Related to #2823 #33
You can use: assignee = condition ? assignment : default(DateTime?)
Seems like a bit of a hack, but I guess it works for now.
This would be addressed by #2823, which is currently on the table for c# 9
Closing as duplicate
No branches or pull requests
I'm trying to assign a value to a null-able type via a tertiary assignment where:
case true: assign non-nullable
case false: assign null
This results in the compile error: Cannot convert DateTime to nullable.
I would assume that the compiler would translate this into something like:
Which compiles fine.
Whats actually going on here?
The text was updated successfully, but these errors were encountered: