星座查询:C#版根据生日查星座
香水坏坏 发表于 2007-8-17 [ASP.NET]
C#版根据生日求星座,算法和我之前写的JAVASCRIPT版有所不同。
JAVASCRIPT版,查看这里:http://www.aspstat.com/30
C#代码
- public string GetAtomFromBirthday(DateTime birthday)
- {
- float birthdayF = 0.00F;
- if (birthday.Month == 1 && birthday.Day < 20)
- {
- birthdayF = float.Parse(string.Format("13.{0}", birthday.Day));
- }
- else
- {
- birthdayF = float.Parse(string.Format("{0}.{1}", birthday.Month, birthday.Day));
- }
- 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};
- string[] atoms = { "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };
- string ret ="靠!外星人啊。";
- for (int i = 0; i < atomBound.Length-1; i++)
- {
- if (atomBound[i] <= birthdayF && atomBound[i + 1] > birthdayF)
- {
- ret = atoms[i];
- break;
- }
- }
- return ret;
- }
访客评论
-
杨本江 [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:
- 评论内容:
- 私人

