Handling Null Values in F#

前端 未结 6 881
不思量自难忘°
不思量自难忘° 2020-12-13 00:25

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 s

6条回答
  •  春和景丽
    2020-12-13 00:52

    If you don't want to do anything in the null case, then you can use the unit value ():

    match value with
    | null -> ()
    | _ -> // your code here
    

    Of course, you could also do the null check just like in C#, which is probably clearer in this case:

    if value <> null then
        // your code here
    

提交回复
热议问题