3 ms·
c# has an option type. You can make any struct type nullable with a ?.
by cdoxsey 8y ago
c# has an option type. You can make any struct type nullable with a ?.
- masklinn 8y agoThe issue is you can't make reference types non-nullable (yet, they're working towards that end for 8.0).
- pred_ 8y agoThose interested in how C# 8.0 approaches the problem might appreciate Mads Torgersen's thoughts on the matter [0] (relevant part starts at 5:40). [0] https://channel9.msdn.com/Blogs/Seth-Juarez/A-Preview-of-C-8-with-Mads-Torgersen https://channel9.msdn.com/Blogs/Seth-Juarez/A-Preview-of-C-8...
- qu4z-2 8y agoDo you know how they're solving the problem of the language expecting a `default(T)` to exist for every type?
- masklinn 8y agoYou can get a pretty complete overview at https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-reference-types-in-csharp/ https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-... But essentially they're not solving it: you will get a warning on explicit default-ing of a non-nullable reference, you will get a warning on implicitly initialising/defaulting class fields, but you will not get warnings when doing so for structs or arrays.
- qu4z-2 8y agoThanks. That looks quite interesting.