【发布时间】:2016-07-19 09:12:58
【问题描述】:
我有一个添加标签页的方法,我为标签页创建了一个字典,因为它们应该显示在它们的每个模式(键)中
我想在 forech 上迭代我的 SwitchMode 方法并添加标签页。
我的代码:
[Flags]
public enum Mode
{
Start = 1,
Test = 1 << 1,
Config = 1 << 2,
}
迭代字典 - > 在这里我需要帮助 - 我如何添加所有标签页,而不仅仅是第一个标签页,这种迭代是否正确?
public void SwitchMode (Mode mode)
{
foreach (var m in _tabDict)
{
if (m.Value == Mode.Start)
{
AddTabPage (_tabDict.First ().Key);
}
if (m.Value == Mode.Test)
{
AddTabPage (_tabDict.First ().Key);
// AddTabPage (_tabDict.All ()); // doesn't work
}
if (m.Value == Mode.Config)
{
AddTabPage (_tabDict.First ().Key);
}
}
}
【问题讨论】:
-
m是 KeyValuePair 并具有Key属性 (m.Key)。是你要找的吗?
标签: c# winforms dictionary foreach