Reputation: 311
I'm trying to do the following F# equivalent:
[C#]
public virtual int Property { get; set; }
But this code (and many other combinations) does not work:
[F#]
abstract member Id: int with get, set
default val this.Id = 123 with get, set
Upvotes: 5
Views: 724
Reputation: 19601
Ok, looking at the MSDN documentation on F# properties, this line in the abstract properties immediately jumps out:
Alternatively, abstract can just mean that a property is virtual, and in that case, a definition must be present in the same class.
The example syntax they give is:
type Base1() =
let mutable value = 10
abstract Property1 : int with get, set
default this.Property1 with get() = value and set(v : int) = value <- v
Now I'm not overly familiar with F#, but my guess is that you could set let mutable value = 10
to your requirement of let mutable value = 123
Upvotes: 1