I've noticed recently that more and more code snippets include variable declarations that happen in the middle of routines. Does this practice have any advantage over declaring all the needed variables at the beginning of a subroutine or function?
thanks all.
g.
thanks all.
g.

AlanRank #669 · 3.6K reputationPosted Mar 19, 2008, 9:45 AM EDT
No, it's just that some programmers prefer to declare their local variables close to where they're first going to be used.
Others (like me) tend to favour declaring them all at the beginning of the method. It's just a matter of taste and doesn't have any advantage one way or the other.
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 13, 2008, 4:34 PM EDT
Hi,
But its always better to delcare all the variabes at one place rather distributing it all the places.
Thanks -- Vj
http://dotnetvj.blogspot.com