日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

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

發布時間:2024/2/28 C# 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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(){InitializeComponent();}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);//直接將返回值輸出到textboxtextBox1.Text += "\r\n" + u.Study();}}public class Student//基類{protected string name;protected int age;public string Study(){string result;result = string.Format("Student({0}):我是基類的方法。我今年{1}歲,我沒畢業,正在學習。\r\n", name, age);return result;}public Student(){this.age = 8;}}public class Undergraguate : Student//派生類 繼承于基類 基類中的函數自動吸收進來{public string subject;//派生類增加的特殊數據成員//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}歲,我畢業了,專業是:{2}\r\n", name, age, subject);return result;}} }

總結

以上是生活随笔為你收集整理的C# 类的派生 输出个人信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。