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;
}
在这一方法中,按理说1.6号为摩羯座,可是按照这个方法,他却是执行了string ret = "日期错误";
之一句,主要是红色字体处不太明白。。能否解释一下,
{
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;
}
在这一方法中,按理说1.6号为摩羯座,可是按照这个方法,他却是执行了string ret = "日期错误";
之一句,主要是红色字体处不太明白。。能否解释一下,
解决方案 »
- 求教.net里使用jquery ajax的方法
- 关于asp.net表单提交验证的疑惑
- Repeater中使用jquery弹层后不触发button事件
- 用存储过程添加记录的问题,急,,,,,,
- 请教一个sql语句
- 各位大哥 谁有网页上文档授权才可以下载的例子啊
- 如何给网站加MSN接口
- linkbutton都失效了(页面上没有验证控件)
- 所有的页面都是报同一个错,急死了。
- ASP.Net操作word,本地调试可行,服务器上.Activate()未将对象引用设置到对象的实例
- List<Translating_model>条件查找
- .NET mvc3.0 在 win7 环境下 session 1分钟就超时。
float birthdayF = 0.00F;
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 };
星座 日期(公历) 英文名
魔羯座 (12/22 - 1/19) Capricorn
水瓶座 (1/20 - 2/18) Aquarius
双鱼座 (2/19 - 3/20) Pisces
牡羊座 (3/21 - 4/20) Aries
金牛座 (4/21 - 5/20) Taurus
双子座 (5/21 - 6/21) Gemini
巨蟹座 (6/22 - 7/22) Cancer
狮子座 (7/23 - 8/22) Leo
处女座 (8/23 - 9/22) Virgo
天秤座 (9/23 - 10/22) Libra
天蝎座 (10/23 - 11/21) Scorpio
射手座 (11/22 - 12/21) Sagittarius
你帖的不全。
http://www.cnblogs.com/shilly/archive/2010/11/15/1877418.html
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 };这个地方
/// 根据生日获取星座
/// </summary>
/// <param name="birthday"></param>
/// <returns></returns>
public static string GeConstellation(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 == "靠!外星人啊。" ? "魔羯座" : ret;
}
我要问的是:
float birthdayF = 0.00F;
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 }
这里怎么理解??????????
atomBound是星座的结尾日期集合,对照2#的贴出来的表
后面的逻辑算出,2月1日出生的属于1.20F-2.20F的范围,水瓶座
初来乍到,所以没见过这种写法,这种写法这能应用于float类型的么?还是都可以??