class Program { struct xs { public string name; public int age; } static void Main(string[] args) { ArrayList al = new ArrayList(); Console.Write("請輸入學生的個數:"); int n = Convert.ToInt32(Console .ReadLine ()); for (int i = 1; i <= n; i++) { xs t = new xs(); Console.Write("輸入第"+i+"個同窗的姓名:"); t.name = Console.ReadLine(); Console.Write("輸入第" + i + "個同窗的年齡"); t.age = Convert.ToInt32(Console .ReadLine ()); al.Add(t); } for (int i = 1; i <= al.Count-1; i++) { for (int j = 1 ; j <= al.Count-i; j++) { if (((xs)al[j]).age >((xs)al[j-1]).age ) { xs tepm = (xs)al[j]; al[j] = al[j - 1]; al[j - 1] = tepm; } } } for (int i = 0; i <al.Count ; i++) { Console.WriteLine("姓名" + ((xs)al[i]).name + "\t" + "年齡" + ((xs)al[i]).age); } Console.ReadLine(); } }