我創建枚舉屬性。這個屬性應該保存到會話中。我的代碼如下所示此錯誤上return Session["Mode"] as TPageMode
如何將枚舉值保存到會話中
The as operator must be used with a reference type or nullable type
當我更換此行
public enum TPageMode { Edit=1,View=2,Custom=3}
protected TPageMode Mode {
get{
if (Session["Mode"] == null)
return TPageMode.Edit;
else
{
return Session["Mode"] as TPageMode; // This row is problem
}
}
set {
Session["Mode"] = value;
}
}
編譯器版本錯誤
return Enum.Parse(typeof(TPageMode), Session["Mode"].ToString());
Cannot implicit convert type 'object' to 'TPageMode'
如何讀取會話中的枚舉值?
不是社區維基... – 2009-09-29 09:10:06