十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
学习Visual Studio时,你可能会遇到Visual Studio Employee类问题,Visual Studio Employee类的派生类型必须具有计算薪水操作,这里将介绍Visual Studio Employee类问题的解决方法,在这里拿出来和大家分享一下。

#t#为Visual Studio Employee类添加一个CalculatePay抽象方法,该方法返回一个十进制数。在Visual Studio Employee类的标题打开其快捷菜单,选择“添加”子菜单和“方法”菜单命令,为新方法命名为“CalculatePay”。在“类详细信息”窗口设置十进制数作为返回类型。该方法应该设置为抽象的。打开CalculatePay方法的快捷菜单并修改“继承修饰符”为abstract(抽象)。然后系统显示一个消息框要求你对这一修改进行确认,选“确定”。
Hourly Employee类应该继承Visual Studio Employee类。这一关系用继承线来创建,具体做法是:将继承线从Hourly Employee类拖到Visual Studio Employee类。
***,为Hourly Employee类添加一个Pay方法。Pay方法只有一个参数,就是工作的小时数。在“类详细信息”窗口,扩展Pay方法的行来打开 “添加参数”项,选择“添加参数”行并输入“Hours”作为参数名,修改类型为十进制数。添加一个HourlyRate属性到该类以使其完整,该属性也是十进制数类型的。
以下代码由类关系图创建。创建的函数是很粗略的,接下来只需要实现这些粗略的函数。
- public interface Iemployee
 - {
 - int Age
 - {
 - get;
 - set;
 - }
 - Name Fullname
 - {
 - get;
 - set;
 - }
 - string EmployeeInfo();
 - }
 - public struct Name
 - {
 - public string FirstName
 - {
 - get
 - {
 - throw new System.NotImplementedException();
 - }
 - set
 - {
 - }
 - }
 - public string LastName
 - {
 - get
 - {
 - throw new System.NotImplementedException();
 - }
 - set
 - {
 - }
 - }
 - }
 - public abstract class Employee : IEmployee
 - {
 - #region IEmployee Members
 - public int Age
 - {
 - get
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - set
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - }
 - public Name Fullname
 - {
 - get
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - set
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - }
 - public string EmployeeInfo()
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - #endregion
 - public abstract decimal CalculatePay();
 - }
 - public class HourlyEmployee : Employee
 - {
 - public decimal HourlyRate
 - {
 - get
 - {
 - throw new System.NotImplementedException();
 - }
 - set
 - {
 - }
 - }
 - public override decimal CalculatePay()
 - {
 - throw new Exception(
 - "The method or operation is not implemented.");
 - }
 - public void Pay(decimal Hours)
 - {
 - throw new System.NotImplementedException();
 - }
 - }