namespace 枚举 { enum city { Beijing, Shanghai, Tianjin = 5, Chongqing } class Program { static void Main(string[] args) { city n; Console.WriteLine("Input a city number({0} to exit):", (byte)city.Beijing - 1); n = (city)Convert.ToByte(Console.ReadLine()); while (n >= city.Beijing) { switch (n) { case city.Beijing: Console.WriteLine("Beijing"); break; case city.Shanghai: Console.WriteLine("Shanghai"); break; case city.Tianjin: Console.WriteLine("Tianjin"); break; case city.Chongqing: Console.WriteLine("Chongqing"); break; default: Console.WriteLine("Invalid city number!"); break; } n = (city)Convert.ToByte(Console.ReadLine()); } } } }运行结果:
enum gender { man, ferman } struct student { public long no, birthday; //学号,生日 public char name; //姓名 public gender sex; //性别 public float score; //成绩 }
namespace 结构 { struct student //学生结构类型 { public string name; public double score; } class Program { static void Main(string[] args) { student[] s = new student[5]; //为学生结构数组赋值 for (int i=0;i<s.Length;i++) { s[i].name = Convert.ToString(Console.ReadLine()); s[i].score = Convert.ToDouble(Console.ReadLine()); } //根据学生的成绩排序 for (int i=0;i<s.Length;i++) { for (int j=i+1;j<s.Length;j++) { if (s[i].score<s[j].score) { student t; t = s[i]; //交换数组元素 s[i] = s[j]; s[j] = t; } } } //依次输出数组元素 for (int i=0;i<s.Length;i++) { Console.WriteLine("{0} {1}", s[i].name, s[i].score); } } } }
运行结果:
原文:http://blog.csdn.net/ry513705618/article/details/24882893