设计如下界面:
编写代码:
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 c
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Student []stu=new Student[100];
int num = 0;
private void button1_Click(object sender, EventArgs e)
{
try
{
stu[num].name = textBox1.Text;
stu[num].grade = Convert.ToDouble(textBox2.Text);
num++;
label3.Text = "成功添加" + num + "条记录";
textBox1.Text = "";
textBox2.Text = "";
}
catch
{
MessageBox.Show("请输入正确的学生信息");
}
}
private void button2_Click(object sender, EventArgs e)
{
double max=stu[0].grade;
foreach(Student i in stu)
{
if(i.grade>max)
{
max = i.grade;
label3.Text = "最高分:" +max+ "\n姓名:"+i.name;
}
}
}
}
struct Student
{
public string name;
public Double grade;
}
}
运行结果: