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

时间:2022-01-10 22:05:00

Is there a way to have a mutable static variable in F# class that is identical to a static variable in C# class ?

有没有办法让F#类中的可变静态变量与C#类中的静态变量相同?

1 个解决方案

#1


13  

You use static let bindings (note: while necessary some times, it's none too functional):

你使用静态let绑定(注意:虽然需要一些时间,但它没有太多功能):

type StaticMemberTest () =

    static let mutable test : string = ""

    member this.Test 

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

#1


13  

You use static let bindings (note: while necessary some times, it's none too functional):

你使用静态let绑定(注意:虽然需要一些时间,但它没有太多功能):

type StaticMemberTest () =

    static let mutable test : string = ""

    member this.Test 

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