using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestStruct { enum Country {中国,韩国,美国,英国} struct Information { public Country con; public int age; } class Program { static void Main(string[] args) { Information stuIn; int country; int age; foreach (String temp in Enum.GetNames(typeof(Country))) { Console.WriteLine("{0}:{1}",temp,Enum.Format(typeof(Country),Enum.Parse(typeof(Country),temp),"d")); } Console.WriteLine("请输入你的国家选项:"); country=Convert.ToInt32(Console.ReadLine()); if (country < 0 || country > 4) { Environment.Exit(0); }; Console.WriteLine("请输入你的年龄"); age=Convert.ToInt32(Console.ReadLine()); if (age < 1 || age >130) { Environment.Exit(0); }; stuIn.con = (Country)country; stuIn.age = age; Console.WriteLine("你的国家是{0},年龄是{1}!",stuIn.con,stuIn.age); Console.ReadLine(); } } }