First, my background is vb/vb.net. Only recently has I dove into c#.net 2005.
My understanding is when declaring a variable, i need to initialize it such as:
int MyCount;
MyCount = 0;
Where I'm confused is if this is a best practice:
int MyCount = 0;
If not, then why? Seems I can do everything on one line instead of two is better.
AlanPosted Oct 4, 2007, 1:02 PM
That's right, Chris.
Unlike VB.Net, local variables are not assigned a default value - you have to give them one before you use them otherwise the C# compiler will complain.
I agree that, where possible, its best to give them a value when you declare them, to save typing and so you don't forget to do this later.