When condition is false, value1 will be 0, and value2 will be null. Although from a compiler perspective this perfectly logical, fallible human beings might expect (and hence miss) that in the first case, the value turns out to be 0, instead of null.
I would propose a rull that, when assigning nullable value types with a ternary conditional operator, the default keyword should be avoided:
That’s quite interesting, I think it could indeed be a new rule idea with the exception of default(T) and default(T?), as you have already noted.
I will assign this to our Product Manager for further evaluation and prioritization.
I stumbled on a bug last week (my own mistake) that could be prevented with this rule. I’m still hoping that it could be implemented. Any idea if this is still on your radar?
I did record this rule idea in our stack of rules to consider, and I promptly forgot to thank you for the idea… So here we go: Thank you!
Right now we are focused on other priorities, though, so I have no timeline for new rules in the coming months. I’m still interested by those nasty gotchas, though, as they will trip even the best of us!