• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C++ Equivalent to C# Dictionary

The nearly exact C++ equivalent to .NET's Dictionary collection is the std::unordered_map collection.

C# C++
using System.Collections.Generic;

void Dictionaries()
{
    Dictionary<string, int> map = new Dictionary<string, int>();
    string s = "test";
    map.Add(s, 1);
    int i = map[s];
    i = map.Count;
    bool b = map.Count == 0;
    map.Remove(s);
}
#include <string>
#include <unordered_map>

void Dictionaries()
{
    std::unordered_map<std::wstring, int> map;
    std::wstring s = L"test";
    map.emplace(s, 1);
    int i = map[s];
    i = map.size();
    bool b = map.empty();
    map.erase(s);
}


Use C# to C++ Converter to convert from C# to C++.     

Additional resource: C++ and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.