using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace 构造函数析构函数 { class Program { static void Main(string[] args) { //不会有c1._name只会有c1. Clerk c1=new Clerk("张三",Gender.男,23,"人力资源"); c1.Write();
Clerk c2= new Clerk("李四",Gender.男,30); c2.Write2();
Console.ReadKey(); } } }
Clerk.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace 构造函数析构函数 { 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 string _department; public string Department { get { return _department; } set { _department = value; } } private int age;//默认是0 public int Age { get { return age; } set { age = value; } } public void Write() { Console.WriteLine("我是{0},{1},{2}岁了,在{3}任职",this.Name,this.Gender,this.Age,this.Department); }
public void Write2() { Console.WriteLine("我是{0},{1},{2}岁了", this.Name, this.Gender, this.Age); }