How to set local variables automatically?

  • Thread starter Thread starter Iwan Petrow
  • Start date Start date
I

Iwan Petrow

Hi,

Are there any options to set local variables in methods automatically
(in Visual Studio 2003)?
Example:

public void Method(){
int i; //I want i=0
ArrayList a; //I want a=null

i++;//compile time error
if (a==null) //compile time error
...

}

Thanks.
 
Iwan Petrow said:
Thanks


But I want this happens automatically. When I write "int i;" i have to
be 0.

You can't, C# requires you to explicitly initalize your locals.

Willy.
 
Iwan Petrow said:
But I want this happens automatically. When I write "int i;" i have to
be 0.

You can't, and I can't see any good reason why you'd want to.

Just declare your variables at the point of first use - that covers
almost all situations, IME, and makes your code clearer.
 
Back
Top