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
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".