我對Enum感到困惑。這是我的枚舉如何從枚舉中獲取字符串值
enum Status
{
Success = 1,
Error = 0
}
public void CreateStatus(int enumId , string userName)
{
Customer t = new Customer();
t.Name = userName;
// t.Status = (Status)status.ToString(); - throws build error
t.Status = //here I am trying if I pass 1 Status ="Success", if I pass 0 Status = "Error"
}
錯誤 - 不能把字符串轉換到enum.Status
public class Customer
{
public string Name { get; set;}
public string Status {get; set;}
}
如何設置客戶的狀態屬性objecj使用枚舉狀態?
(沒有if-else或開關梯)
http://stackoverflow.com/questions/309333/enum-string-name-from-value –
@KeertiSystematixInfotech,感謝有用的鏈接:) –