Results 1 to 2 of 2

Thread: Not sure about this if statement

  1. #1

    Thread Starter
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Not sure about this if statement

    Hi there,

    I am modifying an asp.net site and I stumbled upon this line of code.
    Code:
    //aggregate is bool - which could have been named "canAggregate"
    if (aggregate && Request.QueryString["Aggregate"] != String.Empty && Request.QueryString["Aggregate"] == "1")
    Does that work? As far as I can tell it would be OK but I would have never written that... maybe it's not as wacky as I am thinking it is. In my world I would have first checked for the existence of the query string variable then stopped if it didn't exist (or whatever I needed to do)... Then I would have probably had a this.

    Code:
    if (aggregate &&  (Request.QueryString["Aggregate"] == "1"))
    I know that precedence makes the extra parenthesis unnecessary but for readability I probably would have put them in.

    What does the community think about it? Is it good form? What would you do? I realize that there may be many answers to this question but I just thought I would get some feedback from the people...

    Thanks
    Anti DUPLO machine!!!

  2. #2
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    Re: Not sure about this if statement

    Yours is good. There is no need to check that the string is not equal to string.Empty. If it is "1", it won't be string.Empty, and if it is string.Empty, it won't be "1".
    My monkey wearing the fedora points and laughs at you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width