开发者

F# - public myClass test;

开发者 https://www.devze.com 2023-02-01 11:40 出处:网络
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 proble

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
0

精彩评论

暂无评论...
验证码 换一张
取 消