How can you write the following F# code (or similar) in one line:
let contextMenu = new ContextMenuStrip()
mainForm.ContextMenuStrip <- contextMenu
I have to declare contextMenu as it will be needed later.
I don't recommand you to write it on a single line because this means it will be a mix between the #light (the mode by default now) and non #light syntax. If you really need to, you can use ;; like that:
open System
open System.Windows.Forms
let mainForm = new Form()
let contextMenu = new ContextMenuStrip();; mainForm.ContextMenuStrip <- contextMenu;;
If your expressions have unit type you can use a Sequential Execution Expression, which is an expression of the form:
expr1; expr2; expr3
for instance:
mainForm.ContextMenuStrip <- contextMenu; 5 + 6 |> ignore; mainForm.ContextMenuStrip <- null
I'd like to add that Sequential Execution Expressions have nothing to do with the non #light mode. They are just a general language construct.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With