C#PHP样式数组键

Ozz*_*zzy 3 c# arrays string key

我有一个字符串数组:

String[] array1 = new String[10];
Run Code Online (Sandbox Code Playgroud)

无论如何我可以使用nto数字键吗?

array["keyhere"] instead of array1[1]
Run Code Online (Sandbox Code Playgroud)

谁知道怎么样?

Don*_*nut 7

使用System.Collections.Generic.Dictionary<TKey, TValue>.

例如:

Dictionary<string, string> myDictionary = new Dictionary<string, string>();

myDictionary.Add("key", "value");

string foo = myDictionary["key"];
Run Code Online (Sandbox Code Playgroud)

Dictionary<TKey, TValue>有一些你可能会觉得有用的方法,比如ContainsKey().