I am pulling a ‘long’ value from Session, using a generic property, and it is crashing.
so I have:
public static T Get<T>(string key)
{
if(...)
return (T)System.Web.HttpContext.Current.Session[key];
...
}
When debugging, the value is 4, and it crashes.
If you insist on keeping your generic method, you can use Convert.ChangeType():
That will allow you to call:
But be careful: Convert.ChangeType() doesn’t work for all conversions.