Skip to content

Initialization In F and C #

There are some common compiler tricks in F# and C#, for example object initialization.

In C# 3.0 we have Object Initializers which allow for an object to be instantiated via an explicit constructor call and properties to be set in one statement.

Form f = new Form1()
{
    Text = "Hello"
};
Application.Run(f);

And in F# we have initial property settings where named values are first mapped to constructor parameters and the unused values used to set properties.

> open System.Windows.Forms;;

> let f = new Form(Text = "Hello");;

val f : Form

> f.Show();;
val it : unit = ()

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*