首页 > 解决方案 > 从抽象类 c# 调用方法

问题描述

我需要从类和类中调用CalculateMonthlyPay()方法,知道该怎么做吗?EmployeeFullTimeEmployeePartTimeEmployee

这是我的代码:

public abstract class Employee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public abstract decimal CalculateMonthlyPay();
}

public class FullTimeEmployee
{
    public decimal Salary { get; set; }
}

public class PartTimeEmployee
{
    public decimal HourlyRate { get; set; }
    public double HoursWorked { get; set; }
}

标签: c#

解决方案


尝试这个

public class FullTimeEmployee : Employee
{​​​​​​​
    public decimal Salary {​​​​​​​ get; set; }​​​​​​​

    public override decimal CalculateMonthlyPay()
    {​​​​​​​
        //code here
    }​​​​​​​


}​​​​​​​

推荐阅读