我定义了一个名为myComplex的类。我需要将它映射到整数。在C++中,我会先创建一个map,像这样: map<myComplex,int>
那在C#中怎么实现呢?
我定义了一个名为myComplex的类。我需要将它映射到整数。在C++中,我会先创建一个map,像这样: map<myComplex,int>
那在C#中怎么实现呢?
相当的类别将会是在System.Collections.Generic
命名空间中的 SortedDictionary<TKey, TValue>
类。
如果您不关心顺序,那么System.Collections.Generic
命名空间中的 Dictionary<TKey, TValue>
类可能已经足够。
std::map<Key, Value>
转换为 SortedDictionary<TKey, TValue>
std::unordered_map<Key, Value>
转换为 Dictionary<TKey, TValue>
看一下 System::Collections::Generic 中的 Dictionary 类。
Dictionary<myComplex, int> myMap = new Dictionary<myComplex, int>();
Dictionary<myComplex, int>
,但更多信息会更好。 - gideon