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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();


            }
        }
      
    }

avatar