类Test
在构造时创建另一个类的实例并设置属性看起来像这样(我想):
type Test() as this =
let a = new A()
do this.Init()
member this.Init() =
let a.Size = 10
但是,我得到Block following this 'let' is unfinished. Expect an expression.
这样做的正确和首选方式是什么?
答案 0 :(得分:5)
如果你想改变Size
属性,你必须使用赋值运算符:
type Test() as this =
let a = new A()
do this.Init()
member this.Init() =
a.Size <- 10
但是,您可以更简洁地写出这样的内容:
type Test() =
let a = A (Size = 10)