Public Mutable Field in Object
问题 Is it possible to create a simple public mutable field in F#? I'm creating a library that I will be accessing from a C# program and I need to be able to set a field from C#. //C# Equivalent public class MyObj { public int myVariable; } //F# type MyObj = //my variable here member SomeMethod() = myVariable <- 10 //C# Usage MyObj obj = new MyObj(); obj.myVariable = 5; obj.SomeMethod() 回答1: type MyObj() = [<DefaultValue>] val mutable myVariable : int member this.SomeMethod() = this.myVariable <-