日期的格式 -9-26
//获取日期方式 一般写在需要的类里string test=GetConstellation("-9-26");string GetConstellation(string times){string[] sArray = times.Split('-');//由于日期格式有 - 所以切割一下int month = int.Parse(sArray[1]);//拿到月int day = int.Parse(sArray[2]);//拿到日期if (month == 3 && day >= 21 || month == 4 && day <= 19){return "白羊座";}if (month == 4 && day >= 20 || month == 5 && day <= 20){return "金牛座";}if (month == 5 && day >= 21 || month == 6 && day <= 21){return "双子座";}if (month == 6 && day >= 22 || month == 7 && day <= 22){return "巨蟹座";}if (month == 7 && day >= 23 || month == 8 && day <= 22){return "狮子座";}if (month == 8 && day >= 23 || month == 9 && day <= 22){return "处女座";}if (month == 9 && day >= 23 || month == 10 && day <= 23){return "天秤座";}if (month == 10 && day >= 24 || month == 11 && day <= 22){return "天蝎座";}if (month == 11 && day >= 23 || month == 12 && day <= 21){return "射手座";}if (month == 12 && day >= 22 || month == 1 && day <= 19){return "摩羯座";}if (month == 1 && day >= 20 || month == 2 && day <= 18){return "水瓶座";}if (month == 2 && day >= 19 || month == 3 && day <= 20){return "双鱼座";}return "";}
如果觉得《C# 根据出生日期解析 对应星座》对你有帮助,请点赞、收藏,并留下你的观点哦!