|
|
|
|
|
by MadsTorgersen
3219 days ago
|
|
At first we did think of this as a way to add non-nullable reference types to C#, maybe with a `string!` syntax as you propose. The feature only really started to gel when we realized the important feature was nullable reference types. The thing is, in most code, most things aren't actually supposed to be null. So we want non-null to be the default. When you start marking the things that should be null as such, you'll be protected from dereferencing those without a check. That's what actually prevents you from getting null-reference exceptions! And once you've marked them all (usually a fraction of your type annotations), null really doesn't have a place in the remaining spots, and you can turn on the non-null check to eradicate those. This leaves you with the smallest number of places to update your existing code, and leaves new code the cleanest. |
|