as in C #, in the string [] array add multidimensional type values ​​as in php type of such

$ array ['klucchslovo'] = "znachenie"; - exactly the text

In C #, everyone clapped and did not understand

public string [] arr = {}; I don't know anymore ...

And then how to access these keys

  • + how then to contact these keys - Fuy Cat
  • 7
    You need not an array, but a dictionary. Dictionary<string, string> - tym32167

1 answer 1

Use the dictionary.

Mini example with different dictionary features:

 var myDict = new Dictionary<string, string>() { { "key1", "value1" }, { "key2", "value2" }, }; myDict.Add("key3", "value3"); if(myDict.Keys.Contains("key1")) { Console.WriteLine("key1 is present in myDict"); Console.WriteLine($"its value is={myDict["key1"]}"); } else { Console.WriteLine("key1 is NOT present in myDict"); } Console.WriteLine(); if (myDict.Keys.Contains("key4")) { Console.WriteLine("key4 is present in myDict"); } else { Console.WriteLine("key4 is NOT present in myDict"); } Console.WriteLine(); foreach (var element in myDict) { Console.WriteLine($"key={element.Key},{element.Value}"); } Console.WriteLine(); Console.WriteLine($"Количество элементов {myDict.Count}"); 

Conclusion:

enter image description here

Dictionaries are not only string, begin to study with this example, and then move towards the study of other options.

Related Links: