Access to a dictionary with an array of key values

I have a dictionary with an array in it, which is defined as:

Dictionary<string, string[]> wordDictionary = new Dictionary<string, string[]>(); 

is there any way in c # to access specific values ​​in a dictionary without iterating foreach.

+4
source share
3 answers

Try the following:

 var t = wordDictionary ["myKey"][myArrIndex] 

For example, this will give you the whole array:

 var t = wordDictionary ["myKey"] 

while this will give you the value in the array at position 5:

 var t = wordDictionary ["myKey"][5] 
+6
source

If you know the key, you can access it as follows:

 string[] str=wordDictionary["yourString"]; 
+1
source

How about this?

 string firstFoo = wordDictionary["foo"][0] 
0
source

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


All Articles