What is C# equivalent of in C++? [duplicate]

2019-01-25 01:34发布

问题:

This question already has an answer here:

  • C# equivalent of C++ map<string,double> 8 answers

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#?

回答1:

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.



回答2:

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

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



回答3:

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

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


回答4:

.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