【发布时间】:2019-11-04 05:36:21
【问题描述】:
我有以下代码:
模块 ExchangeSocket =
type Socket(url, id, key) =
let Communicator = new TestCommunicator(url)
let Client = new WebsocketClient(Communicator)
do
Communicator.Name <- "test"
Communicator.ReconnectTimeoutMs <- int (TimeSpan.FromSeconds(30.).TotalMilliseconds)
如果我们看最后两行,C#的用法是这样的:
Communicator = new WebsocketCommunicator(wsUrl) { Name = "tst", ReconnectTimeoutMs = (int) TimeSpan.FromSeconds(30).TotalMilliseconds };
现在我读到要创建一个类构造函数,我必须使用'new'关键字;所以我让字段成员并做一个“新”部分:
member this.communicator : TestCommunicator
member this.client : WebsocketClient
new() =
this.communicator <- new TestCommunicator(url)
this.client <- new WebsocketClient(this.communicator)
但这不起作用(在本例中第 15 行是顶行)
Socket.fs(15, 64): [FS0010] 成员定义中在此点或之前的不完整结构化构造。应为“with”、“=”或其他标记。
我的问题是:
- 如何进行这项工作?
- “新”带来了什么“做”没有?
【问题讨论】: