Obecnie im studiuje C# z ASP.NET MVC 4 z Code First Approach. Im Visual Basic Developer, a teraz chcę uruchomić C#. I teraz znalazłem się w sytuacji, w której muszę zarządzać wieloma dziedziczeniami. Ale nie jest to możliwe w przypadku klasy i. Tak, jak należy zarządzać tych klas mam:C# Dziedziczenie wielokrotne
//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; }
}
Co chcę zrobić jest zatwierdzony, ApprovedDate i ApprovedUserId także wspólne. Chcę określić te właściwości, takie jak:
public class Approve {
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
I chcesz używać jak:
public class Student:Person,Approve
{
public DateTime DateOfBirth { get; set; }
public DateTime EnrollmentDate { get; set; }
public string Remarks { get; set; }
}
I nie mogę umieścić te rzeczy wewnątrz OSOBY. Ponieważ, muszę użyć tego do innych klas, ale nie są to Osoby.
Potem, jak mogę to osiągnąć ...
proszę dać mi przykład dla powyższej sytuacji.
Proszę o pomoc. I, bardzo dziękuję z góry.
W języku C#, można dziedziczyć jedną klasę i wdrożenia wielu interfejsów i trzeba umieścić klasę pierwszą. –
Spróbuj użyć interfejsów – wudzik
Lub użyj Zatwierdź jako właściwość w klasie ucznia –