undeclare varables?

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hi,

Do I need to undeclare variables?
If yes, how?

For example I declare variables inside a while-statement.

Thanks!
 
Arjen,

No, you can not undeclare variables. What are you trying to do?

The only thing you need to be worried about are instances of types that
implement the IDisposable interface, in which case, you need to call the
implementation of Dispose. To make that easier, you have the using
statement.

Hope this helps.
 
What are you trying to do?
Better/cleaner code?
To make that easier, you have the using statement.
I'm allready using this. ;-)

Thanks!


Nicholas Paldino said:
Arjen,

No, you can not undeclare variables. What are you trying to do?

The only thing you need to be worried about are instances of types that
implement the IDisposable interface, in which case, you need to call the
implementation of Dispose. To make that easier, you have the using
statement.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Arjen said:
Hi,

Do I need to undeclare variables?
If yes, how?

For example I declare variables inside a while-statement.

Thanks!
 
Arjen said:
Better/cleaner code?

How would undeclaring a variable give you cleaner code? If you use the
tightest scope available for a variable, I don't think there's much to
be gained beyond that.

I *do* think it's worth using the tightest scope available though - for
instance, using:

for (int i=0; i < 10; i++)
{
....
}

rather than:

int i;
for (i=0; i < 10; i++)
{
....
}
 
In additions, declare variables as close as possible to where they will
be used ...
 
Back
Top