Given an empty pets map, add the mapping from
"rob" to
"dog"
ruby pets['rob']='dog'
pets = []
pets['rob']='dog'
cpp C++/CLI .NET 2.0pets->Add("rob", "dog");
using namespace System;
using namespace System::Collections;
int main()
{
Hashtable^ pets = gcnew Hashtable;
pets->Add("rob", "dog");
}
cpp C++/CLI .NET 2.0pets["rob"] = "dog";
using namespace System;
using namespace System::Collections;
int main()
{
Hashtable^ pets = gcnew Hashtable;
pets["rob"] = "dog";
}
fsharp pets <- (Map.add "rob" "dog" pets)
#light
open System
open System.Collections
let mutable pets = Map.empty
pets <- (Map.add "rob" "dog" pets)
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
fsharp pets.Add("rob", "dog")
#light
open System
open System.Collections
let pets = new Generic.Dictionary<string, string>()
pets.Add("rob", "dog")
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
Submit a new solution for
ruby,
csharp,
cpp, or
fsharp
There are 17 other solutions in
additional languages (
clojure,
erlang,
fantom,
go ...)