Type does not have null as a proper value

前端 未结 2 679
北荒
北荒 2021-01-03 19:08

For the sample program:

type public MyClass(reasonForLiving:string) =
    member x.ReasonForLiving with get() = reasonForLiving

let classFactory () = MyClas         


        
2条回答
  •  无人及你
    2021-01-03 19:42

    Use the [] attribute:

    []
    type public MyClass(reasonForLiving:string) =
        member x.ReasonForLiving with get() = reasonForLiving
    

    By default, F# types do not allow null (thank heavens!). This attribute is useful for interop with other .NET languages and allows assignment/comparison with null.

提交回复
热议问题