PHP Style Array Keys #

I have a string array:

String[] array1 = new String[10];

Anyway, can I use keys that are not numbers?

array["keyhere"] instead of array1[1]

Does anyone know how?

+3
source share
3 answers

Use System.Collections.Generic.Dictionary<TKey, TValue>.

For instance:

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

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

string foo = myDictionary["key"];

Dictionary<TKey, TValue>contains some methods that may be useful to you, for example ContainsKey().

+7
source

Use dictionary

Dictionary<String,Object> phpArray = new Dictionary<String,Object>();
phpArray.Add("keyhere",1);
MessageBox.Show(phpArray["keyhere"]);
+1
source

PHP arrays are called associative arrays. You can use a dictionary or HashMap to implement the same in C #.

0
source

Source: https://habr.com/ru/post/1781543/


All Articles