了解F#中的类构造函数有问题>> [

问题描述 投票:0回答:1
我有以下代码:

模块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”,“ =”或其他标记。

我的问题是:

    如何进行这项工作?
  • “新功能”带来的“做什么”不带来什么?
  • 我有以下代码:模块ExchangeSocket =类型Socket(url,id,key)=让Communicator =新的TestCommunicator(url)让Client =新的WebsocketClient(Communicator)...
  • c# f#
    1个回答
    1
    投票
    现在我读到要创建一个类构造函数,我必须使用'new'关键字
    © www.soinside.com 2019 - 2024. All rights reserved.