Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created June 2, 2011 08:12
Show Gist options
  • Save nagat01/1004102 to your computer and use it in GitHub Desktop.
Save nagat01/1004102 to your computer and use it in GitHub Desktop.
F# static variable,static constructor,destructor
// TODO: Test2's destructor does not work
open System
open System.IO
open System.Net
type Test2() =
// static variable
[<DefaultValue>]
static val mutable private i:int
// static constructor
static do
Test2.i <- 4
Console.WriteLine "inside static constructor.."
// primary constructor
do Console.WriteLine("inside regular constructor..i={0}",Test2.i);
// it aimed to behave as destructor but didn't
override x.Finalize() = Console.WriteLine "destructor(hopefully) called for each object"
Console.WriteLine "Test2"
new Test2() |> ignore
new Test2() |> ignore
Console.ReadKey() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment