Let and Property clause on one line

As you can write the following F # code (or similar) in one line:

let contextMenu = new ContextMenuStrip()
mainForm.ContextMenuStrip <- contextMenu

I need to declare contextMenu as needed later.

+5
source share
3 answers

I do not recommend you write it on one line, because this means that it will be a mixture between #light (the default by default) and non #light syntax. If you really need to, you can use ;; eg:

open System
open System.Windows.Forms

let mainForm = new Form()
let contextMenu = new ContextMenuStrip();; mainForm.ContextMenuStrip <- contextMenu;;

If your expressions are of unit type, you can use Expression Execution Expression, which is a form expression:

expr1; expr2; expr3

eg:

mainForm.ContextMenuStrip <- contextMenu; 5 + 6 |> ignore; mainForm.ContextMenuStrip <- null

, Sequential Execution non #light. .

, .

+6

, .

let contextMenu = new ContextMenuStrip()
let form = new Form(ContextMenuStrip = contextMenu)
+6

You can also enter

let contextMenu = new ContextMenuStrip() in mainForm.ContextMenuStrip <- contextMenu

This is the syntax of OCaml, IIRC.

Edit: to be more clear: this is also valid (#light) F # syntax, since F # is based on OCaml.

I also do not recommend this, although I like short programs.

+5
source

All Articles