c# - 从抽象类 c# 调用方法
问题描述
我需要从类和类中调用CalculateMonthlyPay()
方法,知道该怎么做吗?Employee
FullTimeEmployee
PartTimeEmployee
这是我的代码:
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; }
}
解决方案
尝试这个
public class FullTimeEmployee : Employee
{
public decimal Salary { get; set; }
public override decimal CalculateMonthlyPay()
{
//code here
}
}
推荐阅读
- c# - 如何在 Asp.NET MVC 中修复“此字典需要类型的模型项”?
- java - 如何将字符串添加到二维数组?
- c# - 如何获取 ItemsControl 中所有项目的总高度?
- primefaces - primefaces 6.1 实时滚动只允许在垂直条上滚动,但不能通过水平条滚动
- ios - IOS 的 Flutter 应用程序,是否可以在没有 Xcode 的情况下设置 IOS“旧版构建系统”?
- c# - C#如何获取系统程序集的路径
- f# - 创建一个由 int 和 float 的子集组成的类型'
- java - 使用 testrail 作为 testng 测试的报告器时的 ID 冲突
- android - 在 RecyclerView.ViewHolder 中观察到的 LiveData 值始终为 null(其中数据在 Worker 中更新)
- node.js - 消除子进程数据的缓冲