C#范型学习1

1、使用了C#泛型建立了一个员工信息类,该类中各个成员都具有不同的数据格式。员工信息类如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class Types
    {
       
            public T Num;
            public T Name;
            public T Sex;
            public T Age;
            public T Birthday;
            public T Salary;
    
     }
}

创建了一个泛型类,包含了数据格式不定6个变量。

2、通过泛型集成的形式又为上述的员工添加了三个信息,添加项分别为三项成绩(初学,大牛勿喷)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class Types2 : Types
    {
            public T Chinese;
            public T Math;
            private T English;
            public T Eng
            {
                get
                {
                    return English;
                }
                set
                {

                    English = value;
                
                }
            
            }
    }
}
C#泛型集成格式为

public class type2:type1

3、使用窗体创建如下界面

C#范型学习1_第1张图片

通过显示按钮完成数据的显示,具体显示代码如下所示:

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();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Types2 Exte  = new Types2();
            Exte.Num = 1;
            Exte.Name = "王老师";
            Exte.Sex = "男";
            Exte.Age = "25";
            Exte.Birthday = Convert.ToDateTime("1986 - 06 - 08");
            Exte.Salary = 1500.45F;
            Exte.Chinese = 96;
            Exte.Math = 90;
            Exte.Eng = 86;
            //show the generic to the textbox
            textBox1.Text = Exte.Num.ToString();
            textBox2.Text = Exte.Name.ToString();
            textBox3.Text = Exte.Sex.ToString();
            textBox4.Text = Exte.Age.ToString();
            textBox5.Text = Exte.Birthday.ToString();
            textBox6.Text = Exte.Salary.ToString();
            textBox7.Text = Exte.Math.ToString();
            textBox8.Text = Exte.Eng.ToString();
            textBox9.Text = Exte.Chinese.ToString();                      
        }

       
    }

}
通过直接赋值完成显示,主要学习泛型类的创建和继承操作。 
  


你可能感兴趣的:(c#)