I have this existing code which works very well.
public static T SessionGet<T>(string key)
{
if (Session[key] == null)
return default(T);
else
return (T)Session[key];
}
I wanted to make a version that works for Request. I realise that Request is string based. So how can I change the code so that error, as in the comment below, does not occur without having to place a large switch based on typeof(T).
return (T)Request[key]; // Cannot cast expression of type 'string' to type '(T)'
Here is the function....
public static T RequestGet<T>(string key)
{
if (Request[key] == null)
return default(T);
else
return (T)Request[key];
}
thank you