gpt4 book ai didi

constructor - F#在构造函数中调用成员函数

转载 作者:行者123 更新时间:2023-12-04 13:31:50 27 4
gpt4 key购买 nike

我正在编写一个 F# 类型,但我无法弄清楚如何在初始化时从构造函数中引用成员函数。我想我应该使用 do 绑定(bind),但是 do 绑定(bind)无法理解成员函数。有没有办法解决这个问题?

最佳答案

你可以这样做:

type MyClass() as this =   // Note as this

do this.SayHello()

member this.SayHello() =
do printfn "Hello from constructor!"

但通常这不是一个好习惯

关于constructor - F#在构造函数中调用成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29212553/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com