表驱动法(zz:http://www.cnblogs.com/shinn/archive/2008/04/16/1157141.html)

private static double[] rangeLimit = {  60.0, 75.0, 85.0, 95.0,100.0 };
private static string[] grade = {"不合格", "合乎要求", "良好", "优秀" ,"卓越"};
private static readonly int maxLevel = grade.Length - 1;
public static string CalculateGrade(double score)
{
   int level = 0;
   while (level <= maxLevel)
    {
          if (score < rangeLimit[level])
           {
               return grade[level];
           }
          else

         {

             level++;

          }
    }
    return grade[maxLevel];
}

posted on 2008-09-13 12:07  优雅小猪  阅读(781)  评论(0编辑  收藏  举报

导航