Return (T)Request[key];
<p>I have this existing code which works very well.</p>

<pre><code>public static T SessionGet&lt;T&gt;(string key)
{
    if (Session[key] == null)
        return default(T);
    else
        return (T)Session[key];
}
</code></pre>

<p>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).</p>

<pre><code>return (T)Request[key]; // Cannot cast expression of type 'string' to type '(T)'
</code></pre>

<p>Here is the function....</p>

<pre><code>public static T RequestGet&lt;T&gt;(string key)
{
    if (Request[key] == null)
        return default(T);
    else
        return (T)Request[key];
}
</code></pre>

<p>thank you</p>
