On Mon, 17 Dec 2007 23:49:00 -0800, lianqtlit
<li*******@discussions.microsoft.comwrote:
lets say there are 3 int ncount variable in every method
private void x_method1()
{
int ncount = dv.length;
}
private void x_method2()
{
int ncount = drarr.length;
}
private void x_method3()
{
int ncount = dr.length;
}
Is it best to do this? and why?
[...]
When you say "this", to which example of code are you referring? The one
I quoted? Or the example I left out?
The only reason to put the variable into the class as an instance member
is if it's a value that needs to be accessed by other members in the class
and it would be unavailable otherwise.
In the example you provided, as near as I can tell there's no relationship
between the three different uses of the variable, other than the fact that
it's always a length of something. If the variable was working fine as a
local variable already, then absent any other information I'd say it
should continue to work fine as a local variable and there's no need to
change it to an instance member. It would, in fact, be kind of silly to
do so.
Pete