如何设置Item
结构的值?我尝试了以下两种类型,但都以value must be mutable
错误告终。
module Test1 =
[<Struct>]
type Test (array: float []) =
member o.Item
with get i = array.[i]
and set i value = array.[i] <- value
let test = Test [|0.0|]
test.[0] <- 4.0
module Test2 =
[<Struct>]
type Test =
val mutable array: float []
new (array: float []) = { array = array }
member o.Item
with get i = o.array.[i]
and set i value = o.array.[i] <- value
let test = Test [|0.0|]
test.[0] <- 4.0