【问题标题】:how to use inheritance for inheriting properties form multiple classes?如何使用继承来继承多个类的属性?
【发布时间】:2013-11-14 11:56:29
【问题描述】:

好吧,我的课程很少(Employee、Leaves、Shift、Weekly_off)。我想通过使用员工类对象来访问员工的叶子。叶子和其他人也是如此。所以请帮我解决这个问题。

【问题讨论】:

    标签: c# asp.net interface multiple-inheritance


    【解决方案1】:

    您正在寻找组合,而不是继承:

    public class Employee
    {
        public List<Leave> Leaves { get; set; }
    }
    

    【讨论】:

    • 感谢您的帮助,它没有给我完整的解决方案,但给了我使用 Collections 的技巧。
    【解决方案2】:

    你可以,如果你大写你可以这样输入:

    Employee emp = new EmployeeDerived(); 
    

    但是真的显然还是叶子类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 2017-12-18
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多