3 ms·
Cool stuff. Isn't there still a problem with Option, where when a method takes Option<T> as a parameter, invocations can pass null for that Option<T>? So there'
by bcbrown 12y ago
Cool stuff. Isn't there still a problem with Option, where when a method takes Option<T> as a parameter, invocations can pass null for that Option<T>? So there's still the possibility of null exceptions.
- infogulch 12y agoFrom the article: > Option<T> works in a very similar way to Nullable<T> except it works with all types rather than just value types. It's a struct and therefore can't be null.
- louthy 12y agoExactly. Option<T> has a implicit conversion operator that converts a type of T to Option<T>. So passing T to the function constructs a new Option<T>, and the constructor checks for null. It's also likely (though not guaranteed) that the Option<T> will be allocated on the stack, and should therefore not pose too much of an overhead.
- bcbrown 12y agoAwesome.