HttpContext.Current.Session[propertyCode].ToString()
Will give you problems if the HttpContext.Current.Session[propertyCode]
is null. However is it very hard to see what want to do with you code, maybe you should try to rewrite it like:
public static class SessionHelper
{
public static int PropertyCustCode
{
get
{
int result = 0;
if (int.TryParse(HttpContext.Current.Session[propertyCode], out result){
return result;
}
else
{
throw new Exception("HttpContext.Current.Session[propertyCode] is not a integer");
}
}
set
{
HttpContext.Current.Session[propertyCode] = value.ToString();
}
}
Now you can just do:
SessionHelper.PropertyCustCode = 7777;
int custcode = SessionHelper.PropertyCustCode;