构造函数和析构函数共性:编写代码时,如果没有提供它们,则编译器自动添加。

作用:帮助我们初始化对象(给对象的每个属性依次的赋值)

构造函数是一个特殊的方法:1.构造函数没有返回值,连void也不能写,必须public。 2.构造函数的名称必须和类名一样。

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

namespace ConsoleApplication9
{
public enum Gender
{
,

}
class Clerk
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private Gender _gender;
public Gender Gender
{
get
{
return _gender;
}

set
{
_gender = value;
}
}
private int _age;
public int Age
{
get
{
return _age;
}

set
{
_age = value;
}
}
private string _department;
public string Department
{
get
{
return _department;
}

set
{
_department = value;
}
}
public void Write()
{
Console.WriteLine("我叫{0},我是{1}生,我{2}岁了,在{3}任职",this.Name,this.Gender,this.Age,this.Department);
}
public Clerk(string name,Gender gender,int age,string department)//构造函数
{
this.Name = name;
this.Gender = gender;
this.Age = age;
this.Department = department;
}


}
}


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

namespace ConsoleApplication9
{

class Program
{
static void Main(string[] args)
{
Clerk zsClerk = new Clerk("张三",Gender.,25,"人力部");
zsClerk.Write();
Console.ReadKey();
}
}
}