Export (0) Print
Expand All

do Bindings (F#)

A do binding is used to execute code without defining a function or value. Also, do bindings can be used in classes, see do Bindings in Classes (F#).

[ attributes ]
[ do ]expression

Use a do binding when you want to execute code independently of a function or value definition. The expression in a do binding must return unit. Code in a top-level do binding is executed when the module is initialized. The keyword do is optional.

Attributes can be applied to a top-level do binding. For example, if your program uses COM interop, you might want to apply the STAThread attribute to your program. You can do this by using an attribute on a do binding, as shown in the following code.

open System
open System.Windows.Forms

let form1 = new Form()
form1.Text <- "XYZ"

© 2015 Microsoft