DO绑定用于在不定义函数或类型的情况下执行代码。您可以使用F#中的DO绑定来编写独立的代码。
type DoBindingClass() = class printf "hello" // error : unexpected identifier in member definition end
上面的程序将抛出一个错误,因为在类中使用的PRINT语句。这是不允许直接在课堂上进行的。可以在DO绑定的帮助下执行相同的代码。让无涯教程看看怎么做?
链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-do-bindings.html
来源:LearnFk无涯教程网
type DoBindingClass() = class do printf "Hello FSharp" end new DoBindingClass()
输出:
Hello FSharp
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)