事例讲述Visual Studio Employee类
创始人
2024-06-11 03:20:21
0

学习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属性到该类以使其完整,该属性也是十进制数类型的。

以下代码由类关系图创建。创建的函数是很粗略的,接下来只需要实现这些粗略的函数。

  1. public interface Iemployee  
  2. {  
  3. int Age  
  4. {  
  5. get;  
  6. set;  
  7. }  
  8. Name Fullname  
  9. {  
  10. get;  
  11. set;  
  12. }  
  13. string EmployeeInfo();  
  14. }  
  15. public struct Name  
  16. {  
  17. public string FirstName  
  18. {  
  19. get  
  20. {  
  21. throw new System.NotImplementedException();  
  22. }  
  23. set  
  24. {  
  25. }  
  26. }  
  27. public string LastName  
  28. {  
  29. get  
  30. {  
  31. throw new System.NotImplementedException();  
  32. }  
  33. set  
  34. {  
  35. }  
  36. }  
  37. }  
  38. public abstract class Employee : IEmployee  
  39. {  
  40. #region IEmployee Members  
  41. public int Age  
  42. {  
  43. get  
  44. {  
  45. throw new Exception(  
  46. "The method or operation is not implemented.");  
  47. }  
  48. set  
  49. {  
  50. throw new Exception(  
  51. "The method or operation is not implemented.");  
  52. }  
  53. }  
  54. public Name Fullname  
  55. {  
  56. get  
  57. {  
  58. throw new Exception(  
  59. "The method or operation is not implemented.");  
  60. }  
  61. set  
  62. {  
  63. throw new Exception(  
  64. "The method or operation is not implemented.");  
  65. }  
  66. }  
  67. public string EmployeeInfo()  
  68. {  
  69. throw new Exception(  
  70. "The method or operation is not implemented.");  
  71. }  
  72. #endregion  
  73. public abstract decimal CalculatePay();  
  74. }  
  75. public class HourlyEmployee : Employee  
  76. {  
  77. public decimal HourlyRate  
  78. {  
  79. get  
  80. {  
  81. throw new System.NotImplementedException();  
  82. }  
  83. set  
  84. {  
  85. }  
  86. }  
  87. public override decimal CalculatePay()  
  88. {  
  89. throw new Exception(  
  90. "The method or operation is not implemented.");  
  91. }  
  92. public void Pay(decimal Hours)  
  93. {  
  94. throw new System.NotImplementedException();  
  95. }  

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...