当前位置:编程学习 > C#/ASP.NET >>

高手帮忙解决呀

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();
        }
        //学生类
        public class Student
        {
            private string sno;
            private string name;
            private int chinese;
            private int math;
            private int english;
            public Student(string sno, string name, int chinese, int math, int english)
            {
                this.sno = sno;
                this.name = name;
                this.chinese = chinese;
                this.math = math;
                this.english = english;
            }
            public int sum()      //学生的总成绩
            {
                return chinese + math + english;
            }
            public string sno_get()
            {
                return sno;
            }
            public string name_get()
            {
                return name;
            }
            public int english_get()
            {
                return english;
            }
            public int chinese_get()
            {
                return chinese;
            }
            public int math_get()
            {
                return math;
            }
        }
        //班级类
        public class StudentList
        {
            public Student[] s = new Student[10];
            public static int count = 0;
            public void StudentAdd(string sno, string name, int chinese, int math, int english)
            {
                s[count] = new Student(sno, name, chinese, math, english);
                count++;
            }
            public int Count()
            {
                return count - 1;
            }
            public void StudentSort()      //成绩排序
            {
                Student temp;
                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < count - i - 1; j++)
                    {
                        if (s[j].sum() < s[j + 1].sum())
                        {
                            temp = s[j];
                            s[j] = s[j + 1];
                            s[j + 1] = temp;
                        }
                    }
                }
            }
            public int average()       //平均成绩
            {
                int sm = 0;
                for (int i = 0; i < count; i++)
                {
                    sm += s[i].sum();
                }
                return sm / count;
            }
            public double chinese_max()   //语文最高成绩
            {
                int j = 0;
                for (int i = 0; i < count; i++)
                {
                    if (s[j].chinese_get() < s[i].chinese_get())
                        j = i;
                }
                return s[j].chinese_get();
            }
            public double math_max()   //数学最高成绩
            {
                int j = 0;
                for (int i = 0; i < count; i++)
                {
                    if (s[j].math_get() < s[i].math_get())
                        j = i;
                }
                return s[j].math_get();
            }
            public double english_max()    //英语最高成绩
            {
                int j = 0;
                for (int i = 0; i < count; i++)
                {
                    if (s[j].english_get() < s[i].english_get())
                        j = i;
                }
                return s[j].english_get();
            }
        }
        StudentList sl = new StudentList();
        //添加按钮
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
            {
                MessageBox.Show("学生信息不能为空!");
                textBox1.Text = null;
                textBox2.Text = null;
                textBox3.Text = null;
                textBox4.Text = null;
                textBox5.Text = null;
            }
            else
            {
                string sno = textBox1.Text;
                string name = textBox2.Text;
                int chinese = Convert.ToInt32(textBox3.Text);
                int math = Convert.ToInt32(textBox4.Text);
                int english = Convert.ToInt32(textBox5.Text);
                sl.StudentAdd(sno, name, chinese, math, english);
                MessageBox.Show("学生信息添加成功!");
                textBox1.Text = null;
                textBox2.Text = null;
                textBox3.Text = null;
                textBox4.Text = null;
                textBox5.Text = null;
            }
        }
        //完成按钮
        private void button2_Click(object sender, EventArgs e)
        {
            if (sl.Count() < 2)
            {
                MessageBox.Show("不足三个学生的信息,所以不能显示前三名!");
            }
            else
            {
                sl.StudentSort();
                label6.Text = "第一名是:" + sl.s[0].name_get() + ",总分为" + sl.s[0].sum() + "分\n";
                label6.Text += "\n第二名是:" + sl.s[1].name_get() + ",总分为" + sl.s[1].sum() + "分\n";
                label6.Text += "\n第三名是:" + sl.s[2].name_get() + ",总分为" + sl.s[2].sum() + "分\n";
            }
            for (int i = 0; i < sl.Count() + 1; i++)
            {
                if (sl.s[i].chinese_get() < 60 || sl.s[i].math_get() < 60 || sl.s[i].english_get() < 60)
                {
                    label6.Text += "\n成绩不及格的学生有:" + sl.s[i].name_get() + "\n";
                }
            }
            label6.Text += "\n全班学生的平均成绩为:" + Convert.ToString(sl.average()) + "\n";
            label6.Text += "\n英语学科的最高分为:" + Convert.ToString(sl.english_max()) + "\n";
            label6.Text += "\n语文学科的最高分为:" + Convert.ToString(sl.chinese_max()) + "\n";
            label6.Text += "\n数学学科的最高分为:" + Convert.ToString(sl.math_max());
            label6.Text += null;
        }
        //查询按钮
        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < sl.Count() + 1; i++)
            {
                if (textBox6.Text == sl.s[i].name_get())
                {
                    label7.Text += "\n总成绩为" + Convert.ToString(sl.s[i].sum()) + "分";
                    break;
                }
            }
            label7.Text += null;
        }

    }
}





错误 2 当前上下文中不存在名称“textBox6”
错误 1 类型“WindowsFormsApplication2.Form1”已定义了一个名为“Form1”的具有相同参数类型的成员 --------------------编程问答-------------------- textBox6没有吧 --------------------编程问答-------------------- 你的FORM里有textBox6这个控件么 --------------------编程问答-------------------- 错误 2 当前上下文中不存在名称“textBox6  不存在 。。。这个还用解释么

解决 错误2,1可能就相应解决了。 --------------------编程问答-------------------- 不是把 LZ 这种简单的编译错误 你都看不出来。。
1.txtbox6不存在 要么 你txtbox6名字改了 你没写上txtbox6的名字 要么 压根就没txtbox6
2. 已经有一个Form1了 那么你在定义相同的名称这肯定就冲突了 那么你得改下你的窗体的命名就OK了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,