using System;
using System.Collections;
namespace UCOM.HR{
public class Employee{
public Employee(){
mstrEmpID="999";
mstrEmpName="Miles"; //无参数的构造函数
}
private static string mstrCompanyName="";//这了数据隐藏的特性,这些属性所隐藏的数据都以private的方式声明
private static double mdblBenefit=0;
private string mstrEmpID="";
private string mstrEmpName="";
private static double mdblBaseSalary=0;
public Employee(string EmpID,double BaseSalary){ //构造函数
mstrEmpID=EmpID;
mdblBaseSalary=BaseSalary;
}
public double Salary{ //可读的属性,得到基本工资
get {return mdblBaseSalary+mdblBenefit;}
}
public string EmpID{ //声明一个可读可写员工ID属性
get{return mstrEmpID;}
set{mstrEmpID=value;}
} //为了存取这些private的变量,可以撰写属性操作函数,如员工ID的属性操作函数
public static double Benefit{ //可写不可读属性,写入员工奖金
set{mdblBenefit=value;}
}
public void SetEmpID(string EmpID){ //设置员工ID
mstrEmpID=EmpID;
}
public string GetEmpID(){ //返回员工ID
return mstrEmpID;
}
public void SetEmpName(string EmpName){ //设置员工名字
mstrEmpName=EmpName;
}
public string GetEmpName(){ //返加员工名字
return mstrEmpName;
}
public static void SetCompanyName(string CompanyName){ //设置公司名称
mstrCompanyName=CompanyName;
}
public static string GetCompanyName(){ //得到公司名称
return mstrCompanyName;
}
}
public class HumanResource{
hashtable Employees=new Hashtable();
public Employee this[string EmpID]{
get{return(Employee)Employees[EmpID];}
set{Employees[EmpID]=(Employee)value;}
}
}
public class OtherApp{
public static int Main{
HumanResource Hr=new HumanResource();
Employee.Benefit=1000;
Employee e1=new Employee("001",6000);
Employee e2=new Employee("002",7000);
Hr["001"]=e1;
Hr["001"]=e2;
Employee e3,e4;
e3=Hr["001"];
e4=Hr["002"];
Console.WriteLine("员工三:员工代号={0},薪金={1}",e3.GetEmpID(),e3.Salary);
Console.WriteLine("员工四:员工代号={0},薪金={1}",e4.GetEmpID(),e4.Salary);
return 0;
}
}
}