Udostępnij za pośrednictwem


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

Remarks

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"

[<STAThread>]
do
   Application.Run(form1)

See Also

Reference

Functions (F#)

Other Resources

F# Language Reference