我有一個枚舉型定義,像這樣:轉換的方法參數轉換爲一個枚舉
public enum Status
{
Active=1,
InActive=0
}
在我的方法,我可以投的參數爲枚舉這樣的:
public string doSomething(string param1, int status)
{
//will this work?
Account.Status = (Status) status;
//or do i need to test one by one like this
if(status == 0)
{
Account.Status = Status.Inactive;
//and so on...
} // end if
} // end doSomething
爲什麼不直接運行代碼並找出答案。 – Magnus
@Kaf可能的原因:他使用的數據庫支持'int',但不支持'enum'。 – Nolonar
是的,它會工作。但是,最好檢查int是否在首先聲明的枚舉範圍內。 – VsMaX