C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Non-nullable reference types

Chapter 4: Saying nothing with nullable types: 4.3.1

Created: 2/22/2008
Last updated: 2/22/2008

Just for kicks, imagine a world where all types were non-nullable by default. Sure, the null reference is available when required, but suppose it were prohibited unless you'd explicitly said you'd want to allow it. Any attempt to return a value which might be null could be prohibited in a method declared to return just string, say - whereas if the method were declared to return string? it would be okay.

An alternative which is still possible would be to use ! as a "non-null reference type" modifier. So a method with a signature of void Foo(string! x) would automatically enforce that x wasn't null, etc.

Is it worth it at this point? Probably not - it's one of those ideas which is only really workable if it's present right at the start. There's too much code "out there" now.