开发者

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=""; }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜