This project is read-only.
Invoke win32 API

Category:
InterOp
Description: invoke win23 API to beep on the computer. Please make sure you have sound card installed.
Code:
[]
extern bool MessageBeep(UInt32 beepType);

let InterOpSample1() =
let r = MessageBeep(0xFFFFFFFFu)
printfn "message beep result = %A" r

Execution Result:
message beep result = true

Call .NET functions

Category:
InterOp
Description: Invoke other .NET functions
Code:
let InterOpSample2() = 
let today = DateTime.Today
let tomorrow = today.AddDays(1.0)
let nextWeek = 7.0 |> today.AddDays
printfn "tomorrow = %A" tomorrow
printfn "nextWeek = %A" nextWeek

Execution Result:
tomorrow = 9/13/2011 12:00:00 AM
nextWeek = 9/19/2011 12:00:00 AM

Use List

Category:
InterOp
Description: Use List in .NET
Code:
let InterOpSample3() = 
let shopping = new System.Collections.Generic.List()
shopping.Add("eggs")
shopping.Add("milk")
shopping.Add("bread")
printfn "List: %A" shopping

shopping.Insert(1, "wine")
printfn "List: %A" shopping

shopping.Remove("milk") |> ignore
printfn "List: %A" shopping

Execution Result:
List: seq ["eggs"; "milk"; "bread"]
List: seq ["eggs"; "wine"; "milk"; "bread"]
List: seq ["eggs"; "wine"; "bread"]

Parse number and handle out parameter in C#

Category:
InterOp
Description: Parse number and handle out parameter in C#
Code:
#")>]
let InterOpSample4() =
let parse str =
match System.Decimal.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture) with
| (true, r) -> Some(r)
| (false, _) -> None

printfn "%A" (parse "123")
printfn "%A" (parse "acd")

Execution Result:
Some 123M


Last edited Sep 13, 2011 at 12:36 AM by ttliu2000, version 1

Comments

No comments yet.