Passing Session[] and Request[] to Methods in C#
<p>In C#, How do you pass the Session[] and Request[] objects to a method?</p>

<p>I would like to use a method to parse out Session and Request paramaters for a .aspx page to reduce the size of my Page_Load method. I am passing quite a few variables, and need to support both POSTand GET methods. For most calls, not all variables are present, so I have to test every variable multiple ways, and the code gets long...</p>

<p>This is what I am trying to do, but I can't seem to properly identify the Session and Request paramaters (this code will not compile, because the arrays are indexed by number)</p>

<pre><code>static string getParam(
    System.Web.SessionState.HttpSessionState[] Session,
    System.Web.HttpRequest[] Request,
    string id)
{
    string rslt = "";

    try
    {
        rslt = Session[id].ToString();
    }
    catch
    {
        try
        {
            rslt = Request[id].ToString();
        }
        catch { }
    }

    return rslt;
}
</code></pre>

<p>From Page_Load, I want to call this method as follows to retrieve the "MODE" paramater:</p>

<pre><code>string rslt;
rslt = getParam(Session, Request, "MODE");
</code></pre>

<p>Thanks!</p>
