【发布时间】:2013-08-28 14:13:27
【问题描述】:
目前我正在使用 Code First Approach 使用 ASP.NET MVC 4 研究 C#。我是 Visual Basic 开发人员,现在我想开始 C#。而且,现在我遇到了我必须管理多重继承的情况。但是,我认为 Class 是不可能的。那么,我应该如何管理我拥有的这些课程:
//I have the Following Person Class which Hold Common Properties
//and a Type of Person e.g : Student, Faculty, Administrative
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Type { get; set; }
}
//This is my Student Class, which is Derived from Person
public class Student : Person
{
public DateTime DateOfBirth { get; set; }
public DateTime EnrollmentDate { get; set; }
public string Remarks { get; set; }
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
//This is my Faculty Class, which is also Derived from Person
public class Faculty : Person
{
public DateTime HiredDate { get; set; }
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
我想做的是Approved,ApprovedDate,ApprovedUserId也很常见。我想指定这些属性,例如:
public class Approve {
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
而且,想用like:
public class Student : Person, Approve
{
public DateTime DateOfBirth { get; set; }
public DateTime EnrollmentDate { get; set; }
public string Remarks { get; set; }
}
而且,我不能把这些东西放在 PERSON 里面。因为,我必须将它用于另一个类,但那些不是人。
那么,我该如何实现呢……
请给我一个上述情况的例子。
请帮忙。并且,非常感谢您。
【问题讨论】:
-
在C#中,可以继承一个类,实现多个接口,必须把类放在首位。
-
或者在Student类中使用Approve作为属性
标签: c# c#-4.0 inheritance multiple-inheritance