DateTime date = DateTime.Parse(Console.ReadLine()); //输入生日日期 int month = date.Month; //获取生日月份 int day = date.Day; //获取生日日期

string constellation = ''; //初始化星座字符串

switch (month) { case 1: if (day <= 19) constellation = '魔羯座'; else constellation = '水瓶座'; break; case 2: if (day <= 18) constellation = '水瓶座'; else constellation = '双鱼座'; break; case 3: if (day <= 20) constellation = '双鱼座'; else constellation = '白羊座'; break; case 4: if (day <= 19) constellation = '白羊座'; else constellation = '金牛座'; break; case 5: if (day <= 20) constellation = '金牛座'; else constellation = '双子座'; break; case 6: if (day <= 21) constellation = '双子座'; else constellation = '巨蟹座'; break; case 7: if (day <= 22) constellation = '巨蟹座'; else constellation = '狮子座'; break; case 8: if (day <= 22) constellation = '狮子座'; else constellation = '处女座'; break; case 9: if (day <= 22) constellation = '处女座'; else constellation = '天秤座'; break; case 10: if (day <= 23) constellation = '天秤座'; else constellation = '天蝎座'; break; case 11: if (day <= 22) constellation = '天蝎座'; else constellation = '射手座'; break; case 12: if (day <= 21) constellation = '射手座'; else constellation = '魔羯座'; break; }

Console.WriteLine(constellation); //输出星座名称

C# 使用 switch 语句判断星座

原文地址: https://www.cveoy.top/t/topic/oadU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录