使用C#写一个基本类

2021-05-04 09:26

阅读:462

标签:partial   小学生   sch   data   构造   中学   extc   ring   forms   

1. 设计一个Windows应用程序,在该程序中首先构造一个学生基本类,在分别构造小学生、中学生、中职生、大学生等派生类,要求具有不同的特征和行为,能通过静态成员自动记录不同的学生人数。

 

参考界面如下:

 

 

(1)修改一些控件的属性。

(2)核心代码如下:

  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 WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        public class Student

        {

            private String Name;

            private String Sex;

            private StringSchool;

            private String Grade;

 

 

            public String SName

            {

                get { return Name; }

                set { Name = value; }

            }

            public String SSex

            {

                get { return Sex; }

                set { Sex = value; }

            }

            public String SSchool

            {

                get { return School; }

                set { School = value; }

            }

            public String SGread

            {

                get { return Grade; }

                set { Grade = value; }

            }

 

        }

 

 

        public class A : Student

        {

        }

        public class B : Student

        {

        }

        public class C : Student

        {

        }

        public class D : Student

        {

        }

 

 

 

        public List a = new List();

        public List b = new List();

        public List c = new List();

        public List d = new List();

 

        private void button2_Click(object sender, EventArgs e)

        {

 

            A p = new A();

            p.SName = textBox1.Text;

            p.SSex = textBox2.Text;

            p.SSchool = textBox3.Text;

            p.SGread = textBox4.Text;

            a.Add(p);

            textBox4.Text = "";

            textBox3.Text = "";

            textBox2.Text = "";

            textBox1.Text = "";

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            foreach (A p in a)

            {

                if (p.SName.Equals(textBox1.Text))

                {

                    label5.Text = "姓?名?:êo" + p.SName + "\n"+"性?别àe:êo" + p.SSex +"\n"+ "学?ì校?ê:êo" + p.SSchool+"\n" + "成¨|绩?§:êo" + p.SGread;

 

                }

                else

                {

                    label5.Text = "对?不?起e,ê?没?有?D此??人¨?";

                }

            }

        }

 

        private void label5_Click(object sender, EventArgs e)

        {

 

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

            B p = new B();

            p.SName = textBox5.Text;

            p.SSex = textBox6.Text;

            p.SSchool = textBox7.Text;

            p.SGread = textBox8.Text;

            b.Add(p);

            textBox5.Text = "";

            textBox6.Text = "";

            textBox7.Text = "";

            textBox8.Text = "";

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

            foreach (B p in b)

            {

                if (p.SName.Equals(textBox8.Text))

                {

                    label6.Text = "姓?名?:êo" + p.SName + "性?别àe:êo" + p.SSex + "学?ì校?ê:êo" + p.SSchool + "成¨|绩?§:êo" + p.SGread;

 

                }

                else

                {

                    label6.Text = "对?不?起e,ê?没?有?D此??人¨?";

                }

            }

 

 

 

        }

 

 

 

        private void button5_Click(object sender, EventArgs e)

        {

            C p = new C();

            p.SName = textBox12.Text;

            p.SSex = textBox11.Text;

            p.SSchool = textBox10.Text;

            p.SGread = textBox9.Text;

            c.Add(p);

            textBox12.Text = "";

            textBox11.Text = "";

            textBox10.Text = "";

            textBox9.Text = "";

        }

 

        private void textBox12_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox11_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox10_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox9_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void button6_Click(object sender, EventArgs e)

        {

            foreach (C p in c)

            {

                if (p.SName.Equals(textBox12.Text))

                {

                    label11.Text = "姓?名?:êo" + p.SName + "性?别àe:êo" + p.SSex + "学?ì校?ê:êo" + p.SSchool + "成¨|绩?§:êo" + p.SGread;

 

                }

                else

                {

                    label11.Text = "对?不?起e,ê?没?有?D此??人¨?";

                }

            }

        }

 

        private void label11_Click(object sender, EventArgs e)

        {

 

        }

 

        private void button7_Click(object sender, EventArgs e)

        {

            D p = new D();

            p.SName = textBox16.Text;

            p.SSex = textBox15.Text;

            p.SSchool = textBox14.Text;

            p.SGread = textBox13.Text;

            d.Add(p);

            textBox16.Text = "";

            textBox15.Text = "";

            textBox14.Text = "";

            textBox13.Text = "";

        }

 

        private void textBox16_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox15_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox14_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void textBox13_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void button8_Click(object sender, EventArgs e)

        {

            foreach (D p in d)

            {

                if (p.SName.Equals(textBox16.Text))

                {

                    label16.Text = "姓?名?:êo" + p.SName + "性?别àe:êo" + p.SSex + "学?ì校?ê:êo" + p.SSchool + "成¨|绩?§:êo" + p.SGread;

 

                }

                else

                {

                    label16.Text = "对?不?起e,ê?没?有?D此??人¨?";

                }

            }

        }

 

        private void label16_Click(object sender, EventArgs e)

        {

 

        }

    }

}

 

使用C#写一个基本类

标签:partial   小学生   sch   data   构造   中学   extc   ring   forms   

原文地址:http://www.cnblogs.com/tabs/p/7726301.html


评论


亲,登录后才可以留言!