If we want to access to unmanaged resources from C#,
- The class that indicates unmanaged resource should implement IDisposable interface and override Dispose method.
- When using this class, we should write the code with using () {} clause.
In F#, almost same.
- The class that indicates unmanaged resource should implement IDisposable interface and override Dispose method.
- When using this class, we should write the code with use binding.
> open System;; > type SomeUnmanagedResource() = - interface IDisposable with - member this.Dispose() = - printfn "Some unmanaged resource is diposed.";; type SomeUnmanagedResource = class interface IDisposable new : unit -> SomeUnmanagedResource end > let greetings = - use res = new SomeUnmanagedResource() - printfn "Hello World";; Hello World Some unmanaged resource is diposed. val greetings : unit = ()
No comments:
Post a Comment