Crazy piece of code: Checking query parameter

Posted by Dmytro Shteflyuk on under ASP.NET

How often you are laughing out loud when looking on the someone’s code? Today I found great code in my current project and I can’t hold posting this to my blog. So,

1
2
3
4
5
6
7
8
9
10
11
if (Request.QueryString.HasKeys())
{
    string[] keys = Request.QueryString.AllKeys;
    foreach (string k in keys)
    {
        if (k == "memberpagemode" && (string)Request.QueryString.GetValues(k).GetValue(0) == "edit")
        {
            pSett.ChangeFormViewMode(FormViewMode.Edit);
        }
    }
}

And how do you search through the hash for a key with specified value?