Let's say there is a class that has one open constructor that takes one parameter. In addition, there are several public properties that I would like to set. What will be the syntax for F #? For example, in C #
public class SomeClass { public string SomeProperty { get; set; } public SomeClass(string s) { } }
In F #, I can do this using the property constructor or, but not both at the same time, as in C #. For example, the following are not valid
let sc1 = new SomeClass("", SomeProperty = "") let sc2 = new SomeClass(s = "", SomeProperty = "") let sc3 = new SomeClass("")(SomeProperty = "")
It seems like I'm missing something, but what?
<edit: As David pointed out, all this works in F #, but for some reason, at least for me :), it becomes difficult when the class to be used in F # is defined in C #. For example, with the example TopicDescription (to make something public enough, as for the added example). You can write, for example,
let t = new TopicDescription("", IsReadOnly = true)
and the corresponding compiler error will be Method 'set_IsReadOnly' is not accessible from this code location .
Veksi source share