(no title) (original) (raw)

Ok, this one has me curious.
Why does work:

int valuation = executeFunction(); if (valuation == 0) { string returnvalue = executeotherfunction(); } else { string returnvalue = executeyetanotherfunction(); }

while this one does not... aren't they essentially the same thing?

int valuation = executeFunction(); switch (valuation) { case 0: string returnvalue = executeotherfunction(); break; case 1: string returnvalue = executeyetanotherfunction(); break }

so, scope in an If/Else block is limited to within the block itself, but in a Switch/Case block, scope is exposed to other members?

grrrr.
so I have a switch/case with 6 possibilities, and 6 different variations of "returnvalue","returnval","retval","retvalue","rval", and "rvalue" in them. NICE.

(I greatly simplified it, I realize that in this example I could have defined string returnvalue; outside the switch/case and been ok.)

Edit:
I think you all have missed the point... Ignore this code itself, it was merely an example. What I am getting at is WHY an IF/Else block has local scope for internal variables, while a Switch/Case has method scope for it's declared variables... That is what doesn't make sense to me.. I have the "real" application working, I just don't see WHY it has to work that way.

Hello. I want to share with you my open source project. The purpose of my project is to demonstrate my visual filter builder WPF control in use.…

http://jobsattmp.com/new-york/web-development/dba-sql-server-2005_2008-jobs Hey all, I am trying to hire a DBA in NYC that has a background in MS…

I was always impressed by the bing.com image search AJAX. The bit where where more images load as you scroll down the page. Is there an AJAX control…

Hello. I want to share with you my open source project. The purpose of my project is to demonstrate my visual filter builder WPF control in use.…

http://jobsattmp.com/new-york/web-development/dba-sql-server-2005_2008-jobs Hey all, I am trying to hire a DBA in NYC that has a background in MS…

I was always impressed by the bing.com image search AJAX. The bit where where more images load as you scroll down the page. Is there an AJAX control…