开发者

C# : Can I iterate Dictionary to get each content?

开发者 https://www.devze.com 2023-02-03 09:57 出处:网络
I want to iterate to get into every content in fol开发者_开发百科lowing Dictionary. private Dictionary<Subject, ClassPeriodControl> subjectRects;

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

精彩评论

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

关注公众号