C# : Can I iterate Dictionary to get each content?
I want to iterate to get into every content in fol开发者_开发百科lowing Dictionary.
private Dictionary<Subject, ClassPeriodControl> subjectRects;
I want to access every ClassPeriodControl object in the dictionary.
How can I iterate it?
There is a Values
property of the Dictionary
subjectRects.Values
Just do a foreach loop...pair.Value is the object you want.
foreach (KeyValuePair<Subject, ClassPeriodControl> pair in subjectRects)
{
Console.WriteLine(pair.Value);
}
Dictionary contains collections of keyvaluepair.
So you have to do like
for each KeyValuePair item in subjectRects { item.Subject =""; item.ClassPeriodControl=""; }
精彩评论