C# 类的派生 输出个人信息.docx

上传人:A*** 文档编号:142724393 上传时间:2020-08-22 格式:DOCX 页数:3 大小:45.73KB
返回 下载 相关 举报
C# 类的派生 输出个人信息.docx_第1页
第1页 / 共3页
C# 类的派生 输出个人信息.docx_第2页
第2页 / 共3页
C# 类的派生 输出个人信息.docx_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《C# 类的派生 输出个人信息.docx》由会员分享,可在线阅读,更多相关《C# 类的派生 输出个人信息.docx(3页珍藏版)》请在金锄头文库上搜索。

1、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 派生 public partial class Form1 : Form public Form1() InitializeCom

2、ponent(); private void button1_Click(object sender, EventArgs e) Undergraguate u = new Undergraguate(); string name = textBox2.Text; int age = int.Parse(textBox3.Text); string subject = textBox4.Text; textBox1.Text = u.GetMessage(name, age, subject);/直接将返回值输出到textbox textBox1.Text += rn + u.Study();

3、 public class Student/基类 protected string name; protected int age; public string Study() string result; result = string.Format(Student(0):我是基类的方法。我今年1岁,我没毕业,正在学习。rn, name, age); return result; public Student() this.age = 8; public class Undergraguate : Student/派生类 继承于基类 基类中的函数自动吸收进来 public string su

4、bject;/派生类增加的特殊数据成员 /public Undergraguate()/构造函数 这样就不调用基类的构造函数: base(无名,0)这样调用基类的构造函数 / / subject = 未知; / public Undergraguate() : base()/继承的构造函数 大括号里面还能赋值 本程序中这段代码对输出结果无作用 subject = 软工; age+; public string GetMessage(string name, int age, string subject) this.name = name; this.age = age; this.subject = subject; string result; result = string.Format(Undergraguate(0):我是派生类的方法。我今年1岁,我毕业了,专业是:2rn, name, age, subject); return result;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号