I'm creating enum property. This property should saved into session. My code is here
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;
}
}
compiler release error on return Session["Mode"] as TPageMode
The as operator must be used with a reference type or nullable type
When i replacing this row to
return Enum.Parse(typeof(TPageMode), Session["Mode"].ToString());
This error shown
Cannot implicit convert type 'object' to 'TPageMode'
How to read Enum value from session?