What's the difference between an option type and a nullable type?

Posted by Peter Olson on Stack Overflow See other posts from Stack Overflow or by Peter Olson
Published on 2012-06-21T21:11:23Z Indexed on 2012/06/22 15:16 UTC
Read the original article Hit count: 281

Filed under:
|

In F# mantra there seems to be a visceral avoidance of null, Nullable<T> and its ilk. In exchange, we are supposed to instead use option types. To be honest, I don't really see the difference.

  • My understanding of the F# option type is that it allows you to specify a type which can contain any of its normal values, or None. For example, an Option<int> allows all of the values that an int can have, in addition to None.

  • My understanding of the C# nullable types is that it allows you to specify a type which can contain any of its normal values, or null. For example, a Nullable<int> a.k.a int? allows all of the values that an int can have, in addition to null.

What's the difference? Do some vocabulary replacement with Nullable and Option, null and None, and you basically have the same thing. What's all the fuss over null about?

© Stack Overflow or respective owner

Related posts about F#

Related posts about null