Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Understand C# code

Hello Experts,
I am trying to understand the following line of code.  Any idea what does it do?  Thank you very much in advance.

Thank you

Request.QueryString.GetKey(0)
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thank you it_saige for your time and help.  Yes, you are right.  But still I am not able to understand the logic.  Below is the code.  It returns 3 laters.  I don't understand where from the values are coming.  Please let me know how it happens.  Thank you again!

switch(Request.QueryString.GetKey(0))
{
      case "c":
      case "f":
      case "z":
      default:
}
In your case, the GetKey returns the first key (which by the statement could be c, f, or z).  From the posted code you only care about the key; e.g. -

http://www.somesite.com/somepage.aspx?c=4

Would cause the following in your logic:
switch(/* Request.QueryString.GetKey(0) gets replaced with*/ "c")
{
      case "c":
            // We end up here and perform any statements herein.
            // In order to get the value associated with "c".
            var value = Request.QueryString.Get("c")
            // value = 4.
            break;
      case "f":
            break;
      case "z":
            break;
      default:
            break;
}

Open in new window

-saige-
I am trying to understand where those values "c", "f", "z" are coming from.  Because I don't see anywhere any query is passed during the call.  Also please tell me under what scenario it should be used.  Sorry for the miscommunication.  Thank you.
Thank you  it_saige.   It worked.