Handling Null Values in F#

Viewed 22041

I need to interop with some C# code with F#. Null is a possible value that it is given so I need to check if the value was null. The docs suggest using pattern matching as such:

match value with
| null -> ...
| _ -> ...

The problem I'm having is the original code is structured in C# as:

if ( value != null ) {
    ...
}

How do I do the equivalent in F#? Is there a no-op for pattern matching? Is there a way to check for null with an if statement?

6 Answers

I found a simple way to do this

open System

Object.ReferenceEquals(value, null)
Related