I have the following problem, I want to make an array in C# where the key is a string and then separate the key from the value with a foreach in php I make the array as follows Ex.:
$array['key_name'] = "value1";
I have searched a bit on the internet and found the following:
var datos = new Dictionary<string, string>();
datos ["fondo"] = "LA9018-58-896.png";
datos ["codigo"] = "LA9018";
and to extract the value it would only be like this:
string aValue = datos["fondo"];
what i get
LA9018-58-896.png
The problem I have is that I only get a single key and what I want is to do it dynamically with a foreach . Saving the key in one variable and the value in another .
In C# arrays always have numeric indices.
What you are creating is a ´Dictionary` object in which each element is a key-value pair, in your case both of type string.
You can iterate through the elements of the Dictionary object with a foreach like you do in php. Each element obtained in the iteration will be a key-value pair, so you can access the key through the Key property and the value through the Value property: