Null reference exceptions are one of the top sources of program failures. Tony Hoare called it his billion dollar mistake. So I'm particularly looking forward to C# 8 and the new nullable reference types feature. I think I've got a pretty good grasp of the feature and what it's going to mean for my code. There is one aspect I'm struggling the get my head around though and that's how default will behave.
Currently in C# default(string) will return null. But when C# 8 comes along then doing something like string x = default(string); should surely give a compiler warning straight off the bat. Seems like this is a bit of a paradox. I'm also wondering if default(string?) will be possible and what would it even return. I guess it would have to be null which just adds to my confusion.
I don't think there has been a preview release of this feature yet, but I was wondering if anyone knows yet how this will be handled.
stringwill be an object, thedefault(string)givingnullis pretty much meaningful. - Bharadwaj