Stas
Stas

Reputation:

How to define and use static variables in F# class

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

Upvotes: 9

Views: 5745

Answers (1)

Chris Smith
Chris Smith

Reputation: 18712

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

type StaticMemberTest () =

    static let mutable test : string = ""

    member this.Test 

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

Upvotes: 18

Related Questions