黑马程序员技术交流社区

标题: 复习下this [打印本页]

作者: 胡元江    时间: 2013-2-15 08:46
标题: 复习下this
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();
    }
}
作者: 许庭洲    时间: 2013-2-18 08:35
值得学习ing!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2