對不起,我是相當新的枚舉,我試圖在邏輯上下文中實現它。在我的Employee類中,我創建了一些員工對象。我還爲Employee對象分配狀態創建了一個枚舉。我的目標是創建一個員工列表,併爲每個員工分配一個分配狀態,最後通過列表打印員工數據和員工分配狀態。使用枚舉的對象c#
我想知道:
1 - 這是一個很好的情況下使用枚舉? 2 - 如何爲每個員工分配工作分配狀態?例如,如果我想Emp1有AssignmentStatus.Assigned我應該如何應用此語法明智?
public class Employee
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsCurrentlyEmployed { get; set; }
enum AssignmentStatus
{
Assigned,
Idle,
Trainee,
NotDefined
}
public Employee(int id, string firstName, string lastName, bool isCurrentlyEmployed)
{
Id = id;
FirstName = firstName;
LastName = lastName;
IsCurrentlyEmployed = IsCurrentlyEmployed;
}
public Employee Employees()
{
Employee Emp1 = new Employee(1, "John", "Smith", true);
Employee Emp2 = new Employee(2, "Kevin", "Moore", true);
Employee Emp3 = new Employee(3, "Eric", "Johnson", false);
Employee Emp4 = new Employee(4, "Michell", "McDevour", true);
Employee Emp5 = new Employee(5, "Henry", "Jones", true);
Employee Emp6 = new Employee(6, "Sarah", "Holmes", true);
List<Employee> listEmployees = new List<Employee>();
}
Thnk你
請張貼一些代碼給我們審查和展示一些更多的研究。 – krisdyson 2014-09-22 09:13:02
我的appologies,似乎我沒有發佈的代碼。 – koffe14 2014-09-22 09:14:50
你定義了一個'enum'類型,但你也必須實際使用它。添加一個'AssignmentStatus'類型的屬性。順便說一句,在.NET中,也可以調用該屬性AssignmentStatus。 – 2014-09-22 09:17:36