constructorex.cs

来自「北大青鸟内部资料」· CS 代码 · 共 51 行

CS
51
字号
using System;

namespace Example_3
{

	///<summary>
	/// 此程序演示基类构造函数的初始化过程
	///</summary>


	public class Person
	{
		public string _name;
		public uint _age;

		//基类提供构造函数以进行初始化
		public Person(string name, uint age)
		{
			this._name = name;
			this._age = age;
			Console.WriteLine(_name);
			Console.WriteLine(_age);
		}
	}
	public class Student:Person
	{
		private uint _id;
	
		//调用 Person 构造函数
		public Student(string name, uint age, uint id):base(name, age)
		{
			this._id = id;
			Console.WriteLine(_id);
		}
	}	
	public class Exercise
	{

		///<summary>
		/// 应用程序的主入口点。
		///</summary>
		[STAThread]
		static void Main(string[] args)
		{
			//构造 Student
			Student objStudent = new Student("XYZ", 45, 001);
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?