如何用c语言进行泛式编程

网友投稿 675 2022-08-05

如何用c语言进行泛式编程

如何用c语言进行泛式编程

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

public partial class TypesTClass : Form

{

public TypesTClass()

{

InitializeComponent();

}

///

/// 声明泛型类(声明泛型类的语法与声明普通类是相似的)

///

///

private class Types

{

public T id; //声明编号字段

public T name; //声明姓名字段

public T sex; //声明性别字段

public T age; //声明年龄字段

public T height; //声明身高

public T birthday; //声明出生日期

public T department; //声明工作部门

public T post; //声明岗位

}

///

/// 按钮控件为泛型类中声明的字段进行赋值,并将泛型类中各字段的值显示在文本框中

///

///

///

private void button1_Click(object sender, EventArgs e)

{

Types staff = new Types();//实例化泛型类对象

///为泛型类中声明的字段进行赋值,存储不同类型的值

staff.id = "00358";

staff.name = "李小月";

staff.sex = "女";

staff.age = 27;

staff.height = 1.72F;

staff.birthday = Convert.ToDateTime("1988-02-25");

staff.department = "财物部";

staff.post = "财物主管";

///将泛型类中各字段的值显示在文本框中

textBoxId.Text = staff.id.ToString();

textBoxName.Text = staff.name.ToString();

textBoxSex.Text = staff.sex.ToString();

textBoxAge.Text = staff.age.ToString();

textBoxHeight.Text = staff.height.ToString();

textBoxBirthday.Text = staff.birthday.ToString();

textBoxDepartment.Text = staff.department.ToString();

textBoxPost.Text = staff.post.ToString();

}

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:非计算机专业如何自学c语言?(计算机哪个专业不用学c语言)
下一篇:报班学习c语言费用多少?(C语言报班)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~