Timeline for In C#, why are variables declared inside a try block limited in scope?
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 30, 2017 at 20:01 | audit | First posts | |||
Jul 30, 2017 at 20:01 | |||||
Jul 25, 2017 at 21:32 | comment | added | Kat | @JackAidley especially since you can already write code where you use a variable that might not be assigned. So while Ben's answer has a point about how this is useful behavior, I don't see it as why the behavior exists. Ben's answer does note the OP saying "consistency's sake aside", but consistency is a perfectly fine reason! Narrow scope has all sorts of other benefits. | |
Jul 20, 2017 at 9:01 | comment | added | Jack Aidley | In my opinion, this is the much more fundamental reason, and closer to the "real" answer. | |
Jul 20, 2017 at 3:30 | comment | added | Leliel |
@CompuChip that would have {} pulling double duty as scope and not scope creating depending on context still. try^ //no-scope ^ would be an example of a different marker.
|
|
Jul 19, 2017 at 22:16 | comment | added | CompuChip |
"The only way out of this mess is to designate some other marker to delineate try /catch blocks." - do you mean: try { { // scope } } ? :)
|
|
Jul 19, 2017 at 13:40 | comment | added | JᴀʏMᴇᴇ | Another excellent answer. And I'd never heard of POLA, so nice further reading. Thanks a lot mate. | |
Jul 19, 2017 at 11:27 | history | answered | Peter M | CC BY-SA 3.0 |