实现效果:
知识运用:(泛型类)
类修饰符 class 类名 <类型参数T>
{ 类体 }
实现代码:
class Types <T>{ public T Num; public T Name; public T Sex; public T Age; public T Birthday; public T Salary; } private void button1_Click(object sender, EventArgs e) { Types<object> Extens = new Types<object>(); //创建泛型对象 Extens.Num = 008; //为泛型中声明的字段进行赋值 Extens.Name = "李哪吒"; Extens.Sex = "男"; Extens.Age = 3000; Extens.Birthday = Convert.ToDateTime("1110-09-08"); Extens.Salary=99999.999F; //显示在文本框中 textBox1.Text=Extens.Num.ToString(); textBox2.Text=Extens.Name.ToString(); textBox3.Text=Extens.Sex.ToString(); textBox4.Text=Extens.Age.ToString(); textBox5.Text=Extens.Birthday.ToString(); textBox6.Text = Extens.Salary.ToString(); }