我有了下面的代码的程序:使此代码片断更好
foreach (string section in DataAccessLayer.AcceptedSections)
{
switch (section)
{
case "Section1":
Console.WriteLine("Section 1");
break;
case "Section2":
Console.WriteLine("Section 2");
break;
case "Section3":
Console.WriteLine("Section 3");
break;
default:
Console.WriteLine("Default section");
break;
}
}
有反正我能做到这一点的代码做什么,而不情况下,内再次提供了部分的字符串? DataAccessLayer.AcceptedSections是动态的,我不希望为我的代码添加另一部分案例,每次新章节出现时都会重新编译和重新部署。这是星期五,我的思想不太好。
例如: 我不想添加以下代码,当第4节被添加到数据库中:
case "Section4":
Console.WriteLine("Section 4");
break;
那么你的'Accepte自定义属性dSections'表看起来像? – hunter 2011-04-15 19:05:27
属于CodeReview.StackExchange.Com – 2011-04-15 19:06:23
他们都是很好的答案,我对所有答案都+1,但对于我的情况,字典工作得最好,因为我能够附加我想要执行的方法。 – capdragon 2011-04-15 19:36:42