all groups > c# > april 2005 >
You're in the

c#

group:

How to set local variables automatically?


How to set local variables automatically? Iwan Petrow
4/12/2005 11:57:21 PM
c#:
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.
Re: How to set local variables automatically? Iwan Petrow
4/13/2005 4:05:18 AM
Thanks


But I want this happens automatically. When I write "int i;" i have to
be 0.
Re: How to set local variables automatically? Willy Denoyette [MVP]
4/13/2005 1:15:46 PM

[quoted text, click to view]

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

Willy.

Re: How to set local variables automatically? Michael C
4/13/2005 5:17:50 PM
int i = 0
ArrayList a = null


[quoted text, click to view]

Re: How to set local variables automatically? Jon Skeet [C# MVP]
4/13/2005 9:38:20 PM
[quoted text, click to view]

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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button