I have code where this is declared:
public IDictionary<string, OPTIONS> dict_Options = new Dictionary<string, OPTIONS>();
public class OPTIONS
{
public string subjectId = string.Empty;
public string varNumber = string.Empty;
public string varName = string.Empty;
}
What's the easiest way to iterate over all the varNames in my dictionary object? Is there like a foreach?
foreach (var item in dict_Options)
{
string varName = item.Value.varName;
}
This iterates through all the KeyValuePair<T, T>
in your dictionary
Just to add an alternative to the great answers already posted, you could do:
dict_Options.Keys.ToList().ForEach(m => SomeFunc(m.Value.varName));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With