using System;
class Employee
{
private string name;
private string alias;
private decimal salary = 3000.00m;
public Employee(string name, string alias)
{
//限定同名的隐藏成员
this.name = name;
this.alias = alias;
}
public void printEmployee()
{
Console.WriteLine("姓名: {0} ", name );
//将对象传递到属于其他类的方法 CalcTax
Console.WriteLine("税额: {0:C}", Tax.CalcTax(this));
}
public decimal Salary
{
get { return salary; }
}
}
class Tax
{
public static decimal CalcTax(Employee E)
{
return 0.08m * E.Salary;
}
}
class MainClass
{
static void Main()
{
Employee E1 = new Employee("小胡童鞋","没用么" );
E1.printEmployee();
Console.ReadKey();
}
} |
|