创建控制台应用程序,使用构造函数,从程序结果分析中体会构造函数的使用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConstructFunction
{
    
    
        class Employee
        {
            private string _name;
            private char _gender;
            private string _qualification;
            private uint _salary;
            private Employee()//默认构造函数
            {
                _qualification = "大学毕业生";

            }
            private Employee(string strQualification,string strName,char gender,uint empSal)//参数化构造函数
            {
                _qualification = strQualification;
                _name = strName;
                _gender = gender;
                _salary = empSal;
            }
            static void Main(string[] args)
            {
                Employee objGreduate = new Employee();//调用默认构造函数
                Employee objMBA = new Employee("ACCPS3", "赖卓成", '男', 5500);
                Console.WriteLine("默认构造函数输出:\n资格:=" +objGreduate._qualification);
                Console.WriteLine("参数化构造函数输出:\n资格:=" + objMBA._qualification);
                Console.ReadKey();


            }
        }
      
    }

猜你喜欢

转载自blog.csdn.net/laizhuocheng/article/details/89402523
今日推荐