//我相信LZ更不愿意这样写:
string constellation;
switch(month_day)
{
 case:"0321":
 case:"0322":
 ...
 case:"0420":constellation="白羊";break;
 case:"0421":
 case:"0422":
 ...
 case:"0521":constellation="金牛";break;
 ...
}
//有必要一定要用switch吗?

解决方案 »

  1.   

    晕,中间敲多了个冒号:
    //我相信LZ更不愿意这样写:
    string constellation;
    switch(month_day)
    {
     case "0321":
     case "0322":
     ...
     case "0420":constellation="白羊";break;
     case "0421":
     case "0422":
     ...
     case "0521":constellation="金牛";break;
     ...
    }
    //有必要一定要用switch吗?
      

  2.   


    if(x>321&& x<420)
    {
    .....
    }
    else if(...)
    {
    .....
    }
    ......
      

  3.   

    可以考虑这么做,不知道是不是比if else if效果好……
            int monthDay = int.Parse("0609");
            int month = month / 100;
            int day = month % 100;
            switch (month)
            {
                case 3: result = (day < 21) ? enumHoroscope.Pisces : enumHoroscope.Aries; break;
            }
      

  4.   

    5楼笔误,晕了
            int monthDay = int.Parse("0609"); // try+catch
            int month = monthDay / 100; // 1~12?
            int day = monthDay % 100; // 1~31? Feb 30? Apr 31?
            switch (month)
            {
                case 3: result = (day < 21) ? enumHoroscope.Pisces : enumHoroscope.Aries; break;
            }
      

  5.   

    sql得case when then 语句