码迷,mamicode.com
首页 > Windows程序 > 详细

c#复习-2

时间:2016-06-16 23:03:24      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

输入三个学生的信息
学号、姓名、分数
从大到小排序
1
using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 7 namespace 复习CS 8 { 9 class Program 10 { 11 struct Student 12 { 13 public int num; 14 public string Code; 15 public string Name; 16 public decimal Score; 17 } 18 19 static void Main(string[] args) 20 { 21 //1、循环添加学生信息 22 ArrayList list = new ArrayList(); 23 24 for (int i = 1; i < 4; i++) 25 { 26 Student s = new Student(); //实例化 27 28 Console.Write("请输入第" + i + "个学生的学号:"); 29 s.Code = Console.ReadLine(); 30 Console.Write("请输入第" + i + "个学生的姓名:"); 31 s.Name = Console.ReadLine(); 32 Console.Write("请输入第" + i + "个学生的成绩:"); 33 s.Score = Convert.ToDecimal(Console.ReadLine()); 34 s.num = i; 35 36 list.Add(s); 37 Console.WriteLine("==============================="); 38 } 39 40 Console.WriteLine("-----------------------学生数据展示--------------------------"); 41 42 //2、排序 43 44 for (int i = 0; i < list.Count - 1; i++) 45 { 46 for (int j = i + 1; j < list.Count; j++) 47 { 48 Student s1 = (Student)list[i]; 49 Student s2 = (Student)list[j]; 50 51 if (s1.Score < s2.Score) 52 { 53 Object ob = list[i]; 54 list[i] = list[j]; 55 list[j] = ob; 56 } 57 } 58 } 59 60 //3、打印 61 foreach (object o in list) 62 { 63 Student ss = (Student)o; 64 Console.WriteLine("" + ss.num + "个学生的学号:" + ss.Code + ",姓名:" + ss.Name + ",分数:" + ss.Score + ""); 65 } 66 67 68 69 Console.ReadKey(); 70 } 71 } 72 }

技术分享

c#复习-2

标签:

原文地址:http://www.cnblogs.com/tonyhere/p/5592236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!