#region 获取星座
/// <summary>
/// 获取星座
/// </summary>
/// <param name="birthMonth">月</param>
/// <param name="birthDate">日</param>
/// <returns></returns>
public static Constellation GetConstellation(int birthMonth, int birthDate)
{
float birthdayF = birthMonth == 1 && birthDate < 20 ?
13 + birthDate / 100f :
birthMonth + birthDate / 100f;
float[] bound = { 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 };
Constellation[] constellations = new Constellation[12];
for (int i = 0; i < constellations.Length; i++)
constellations[i] = (Constellation)(i + 1);
for (int i = 0; i < bound.Length - 1; i++)
{
float b = bound[i];
float nextB = bound[i + 1];
if (birthdayF >= b && birthdayF < nextB)
return constellations[i];
}
return Constellation.天蝎座;
}
#endregion
c#获取星座
最新推荐文章于 2021-11-04 11:48:49 发布