如图这样、结果要显示在页面上
通过TextBox1 button label 来完成
网页的
最简单的,假设姓名是textBox1 textBox2 textBox3,对应的成绩是textBox4 textBox5 textBox6
编写代码
TextBox[] txtNames = {textBox1,textBox2,textBox3};
TextBox[] txtCourses = {textBox4,textBox5,textBox6};
var result = txtNames.Zip(txtCourses, (x, y) => new Course(x.Text, "课程", 学分, int.Parse(y.Text))).OrderBy(x => x.Score);
label.Text = string.Join("<br />", result.Select(x => x.Name + "," + x.Score));
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
namespace xsgl
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string [] name = new string [3];//姓名
string [] courseName = new string [3];//课程名
int[] score = new int [3];//成绩
int[] credit = new int [3];//学分
Course s = new Course("", "", 0, 0);
List<Course> students = new List<Course>();
name[0] = TextBox1.Text;
courseName [0] = TextBox3.Text;
credit [0] = Convert.ToInt32(TextBox2.Text);
score [0] = Convert.ToInt32(TextBox4.Text);
name[1] = TextBox5.Text;
courseName[1] = TextBox6.Text;
credit[1] = Convert.ToInt32(TextBox7.Text);
score[1] = Convert.ToInt32(TextBox8.Text);
name[2] = TextBox9.Text;
courseName[2] = TextBox10.Text;
credit[2] = Convert.ToInt32(TextBox11.Text);
score[2] = Convert.ToInt32(TextBox12.Text);
students.Add(s);
foreach (var stu in students.OrderByDescending(p => p.Zf()))
{
Label1.Text = stu.Name + " " + stu.Zf();
}
}
}
}
namespace xsgl
{
public class Course
{
private string courseName;
private int credit;
//课程名称
public string CourseName
{
get
{
return courseName;
}
set
{
courseName = value;
}
}
//课程学分
public int Credit
{
get
{
return credit;
}
set
{
credit = value;
}
}
//学生姓名
public string Name
{
get;
set;
}
//成绩分数
public int Score
{
get;
set;
}
//计算总分
public int Zf()
{
return Credit + Score;
}
public Course(string name, string courseName, int score, int credit)
{
Name = name;//姓名
CourseName = courseName; //书名
Score = score; //成绩
Credit = credit;//学分
}
}
}