C# equivalent of C++ map<string,double> C# equivalent of C++ map<string,double> arrays arrays

C# equivalent of C++ map<string,double>


Roughly:-

var accounts = new Dictionary<string, double>();// Initialise to zero...accounts["Fred"] = 0;accounts["George"] = 0;accounts["Fred"] = 0;// Add cash.accounts["Fred"] += 4.56;accounts["George"] += 1.00;accounts["Fred"] += 1.00;Console.WriteLine("Fred owes me ${0}", accounts["Fred"]);


Dictionary<string, double> accounts;


Although System.Collections.Generic.Dictionary matches the tag "hashmap" and will work well in your example, it is not an exact equivalent of C++'s std::map - std::map is an ordered collection.

If ordering is important you should use SortedDictionary.