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?
Use System.Collections.Generic.Dictionary<TKey, TValue>.
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().
Dictionary<TKey, TValue>
ContainsKey()
Use dictionary
Dictionary<String,Object> phpArray = new Dictionary<String,Object>(); phpArray.Add("keyhere",1); MessageBox.Show(phpArray["keyhere"]);
PHP arrays are called associative arrays. You can use a dictionary or HashMap to implement the same in C #.
Source: https://habr.com/ru/post/1781543/More articles:Что вызывает повышение: ниже, чтобы не выполнить is_singular утверждение? - c++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1781539/passing-parameters-to-urls-in-struts2&usg=ALkJrhgeeOREO4GC0h0MEwSuMtH7KKh8FAПорядок сортировки в Core Data с мульти-мультизависимостью - iphoneUsing the thinking of the Sphinx and staying DRY (do not repeat yourself) - ruby-on-railsRandom javascript color with 7digits should - javascriptHow unison decides how to synchronize a file - synchronizationThe PROMOTE TRANSACTION request failed because the local transaction is inactive - .net-4.0ASP.NET MVC 2: view subfolders? - asp.net-mvc-2Linq to Entities in EF4 using generated POCO classes - entity-frameworkPaperclip: Missing Image - ruby-on-railsAll Articles