如何在F#类中定义和使用静态变量

时间:2020-03-05 18:53:24  来源:igfitidea点击:

有没有办法在Fclass中具有与Cclass中的静态变量相同的可变静态变量?

解决方案

回答

我们使用static let绑定(注意:虽然有时需要,但功能不太强大):

type StaticMemberTest () =

    static let mutable test : string = ""

    member this.Test 

        with get() = 
            test <- "asdf"
            test