朱一 63
牛二 73
张三 89
李四 94
王五 85
........如上格式.求段按考试成绩高低排序的源码 输出结果应该是:
李四 94
张三 89
王五 85
牛二 73
朱一 63

解决方案 »

  1.   

    seelct * from tb order by score desc
      

  2.   

    seelct * from tb order by score desc
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                List<Student> list = new List<Student>();
                list.Add(new Student("张三 ", 89));
                list.Add(new Student("王五", 85));
                list.Add(new Student("李四", 94));
                list.Add(new Student("牛二", 73));
                list.Add(new Student("朱一", 63));
                list.Sort();
                dataGridView1.DataSource = list;
            }
        }
        class Student : IComparable<Student>
        {
            public int CompareTo(Student stu)
            {
                return stu.score.CompareTo(this.score);
            }
            public Student()
            {
            }
            public Student(String name, int score)
            {
                this.name = name;
                this.score = score;
            }
            private String name;        public String Name
            {
                get { return name; }
                set { name = value; }
            }
            private int score;        public int Score
            {
                get { return score; }
                set { score = value; }
            }
        }
    }
      

  4.   

    seelct * from tb order by score desc
    +1- -