Saturday, April 20, 2013

ConcurrentDictionary on F#

(In learning from "Programming F# 3.0, 2nd Edition")

While Dictionary has syntax sugar for F# (check also phosphorescence: Studying F# : Dictionary (a.k.a. Hash or Map)), System.Collections.Concurrent.ConcurrentDictionary has not. So that we use it manually.
> open System.Collections.Concurrent;;
> let concurrentDict = new ConcurrentDictionary<int, string>();;

val concurrentDict : ConcurrentDictionary<int,string> = dict []

> concurrentDict.TryAdd(1, "one");;
val it : bool = true
> concurrentDict.TryAdd(2, "two");;
val it : bool = true
> concurrentDict.TryAdd(3, "three");;
val it : bool = true
> concurrentDict.TryAdd(4, "four");;
val it : bool = true

No comments:

Post a Comment