What is C# equivalent of <map> in C++?

C#C++DictionaryVisual C++Language Comparisons

C# Problem Overview


I have defined a class myComplex. I need to map it to integers. In C++ I would have created a map as map<myComplex,int> first;

How to do such thing in C#?

C# Solutions


Solution 1 - C#

The equivalent would be class SortedDictionary<TKey, TValue> in the System.Collections.Generic namespace.

If you don't care about the order the class Dictionary<TKey, TValue> in the System.Collections.Generic namespace would probably be sufficient.

Solution 2 - C#

std::map<Key, Value>SortedDictionary<TKey, TValue>

std::unordered_map<Key, Value>Dictionary<TKey, TValue>

Solution 3 - C#

Take a look at the Dictionary class in System::Collections::Generic.

Dictionary<myComplex, int> myMap = new Dictionary<myComplex, int>();

Solution 4 - C#

.NET Framework provides many collection classes too. You can use Dictionary in C#. Please find the below msdn link for details and samples http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbhash Kumar SinghView Question on Stackoverflow
Solution 1 - C#dalleView Answer on Stackoverflow
Solution 2 - C#hansmaadView Answer on Stackoverflow
Solution 3 - C#The Forest And The TreesView Answer on Stackoverflow
Solution 4 - C#Karthik KalyanasundaramView Answer on Stackoverflow