我有以下员工类和员工状态枚举:
public class Employee
{
public int ID { get; set; }
public int ClockNo { get; set; }
public string FirstName { get; set; }
public string MiddleInitial { get; set; }
public string LastName { get; set; }
public EmployeeStatus Status { get; set; }
}
public enum EmployeeStatus : int
{
New = 1,
Experienced = 2,
Terminated = 3
}
我只想让枚举可用于Employee类,所以我尝试嵌套它:
public class Employee
{
public int ID { get; set; }
public int ClockNo { get; set; }
public string FirstName { get; set; }
public string MiddleInitial { get; set; }
public string LastName { get; set; }
public EmployeeStatus Status { get; set; }
enum EmployeeStatus : int
{
New = 1,
Experienced = 2,
Terminated = 3
}
}
我找不到EmployeeStatus的编译时错误。我该如何处理这个问题?我希望我的员工状态仅限于一组我硬编码并且智能感知可供我使用的选项。
答案 0 :(得分:3)
除非您将枚举公开,否则您无法在类中嵌套枚举。将枚举设为私有状态,同时通过公共属性(public EmployeeStatus Status { get; set; }
)显示它将导致此错误。
要么将枚举公开,要么将属性设为私有。