星座查询:C#版根据生日查星座

香水坏坏 发表于 2007-8-17 [ASP.NET]

C#版根据生日求星座,算法和我之前写的JAVASCRIPT版有所不同。

 JAVASCRIPT版,查看这里:http://www.aspstat.com/30

C#代码
  1. public string GetAtomFromBirthday(DateTime birthday)   
  2. {   
  3.     float birthdayF = 0.00F;   
  4.   
  5.     if (birthday.Month == 1 && birthday.Day < 20)   
  6.     {   
  7.         birthdayF = float.Parse(string.Format("13.{0}", birthday.Day));   
  8.     }   
  9.     else  
  10.     {   
  11.         birthdayF = float.Parse(string.Format("{0}.{1}", birthday.Month, birthday.Day));   
  12.     }   
  13.     float[] atomBound ={1.20F,2.20F,3.21F,4.21F,5.21F,6.22F,7.23F,8.23F,9.23F,10.23F,11.21F,12.22F,13.20F};   
  14.     string[] atoms = { "水瓶座""双鱼座""白羊座""金牛座""双子座""巨蟹座""狮子座""处女座""天秤座""天蝎座""射手座""魔羯座" };   
  15.   
  16.     string ret ="靠!外星人啊。";   
  17.     for (int i = 0; i < atomBound.Length-1; i++)   
  18.     {   
  19.         if (atomBound[i] <= birthdayF && atomBound[i + 1] > birthdayF)   
  20.         {   
  21.             ret = atoms[i];   
  22.             break;   
  23.         }   
  24.     }   
  25.     return ret;   
  26. }  
9013 13 标签:C# 星座 
访客评论
  • 杨本江    [2009-6-9]
    我想查我的星座
  • 杨本江    [2009-6-9]
    我想查我的星座
  • 伟大    [2008-3-25]
    楼下的你很伟大
  • 方健    [2008-3-24]
    我爱我的女朋友
  • 香水坏坏    [2007-11-22]
    Re:s777n

    不错,解法挺精练的
  • s777n    [2007-11-22]
    加号被自动去除了
    ("摩羯,水瓶,双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯").Split(',')[dt.Day < (20 + int.Parse(("2101122344432")[dt.Month].ToString())) ? dt.Month - 1 : dt.Month] + "座"
  • s777n    [2007-11-22]
    费那事干嘛。 曾经做过的,一句搞定。
    ("摩羯,水瓶,双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯").Split(',')[dt.Day < (20 int.Parse(("2101122344432")[dt.Month].ToString())) ? dt.Month - 1 : dt.Month] "座"
  • 飞过海    [2007-11-21]
    1986 1 28
  • wangguangping    [2007-10-27]
    1989/05/01
  • 韩立洋    [2007-10-18]
    2000年11月27日11点35分出生查星座
发表评论
  • 你的姓名:
  • 你的网站:
  •   EMAIL:   
  • 评论内容:
  • 私人