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 = "日期错误";
之一句,主要是红色字体处不太明白。。能否解释一下,

解决方案 »

  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 };
      

  2.   

    float[] atomBound 里面的是星座结尾日期的格式
    星座 日期(公历) 英文名 
    魔羯座 (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
      

  3.   

    你的连接中,还是不明白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 };这个地方
      

  4.   

            /// <summary>
            /// 根据生日获取星座
            /// </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;
            }
      

  5.   

    我知道怎么获取
    我要问的是:
    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 }

    这里怎么理解??????????
      

  6.   

    birthdayF是指当前输入生日的系数,比如你是2月1日出生的,就是2.1F,3月20日出生的就是3.20F
    atomBound是星座的结尾日期集合,对照2#的贴出来的表
    后面的逻辑算出,2月1日出生的属于1.20F-2.20F的范围,水瓶座
      

  7.   

    float birthdayF = 0.00F;
    初来乍到,所以没见过这种写法,这种写法这能应用于float类型的么?还是都可以??