I'm fairly need to this whole F# thing and Func开发者_高级运维tional programming.. I've been looking in all possible documents and found nothing, so therefore I ask you for help for my simple problem. How do I declare:
public myClass test;
in F#?
If you want the declaration to go in the module, do
let test = myClass()
If you want the declaration to go in the class, do
val test: myClass
You'll have to initialize test in the constructor, or to provide a DefaultValue attribute:
[<DefaultValue>]
val mutable test: myClass
Then it will be default-initialized to null
.
The final alternative is to have the private field (then you can initialize it inside the class declaration) and provide an accessor:
let test = myClass()
member x.Test = test
or
let mutable test = myClass()
member x.Test with get () = test and set value = test <- value
精彩评论