C# Variables problem

liunx

Guest
I'm currently new to C#, i'm VB Developer my question is that, must i gives values to varibales when i declare it, when i dont do that i have this error

Use of unassigned local variable 'CatID'

and here's what i do
int CatID; :oNo, you can do them later. However if you then try to use them before you do asign something then you will get a nullpointerexception.You do not have to initialise your variables when you declare them. But it is advisable to initialise them to your default values. If you do not the system initialises them for you (but you will not be sure what the default are) when you declare them or soon after declaration.
The answer is NO, in C# you do not have to initialise your variable when you declare them.
e.g.
int x;
bool isValid;
 
Back
Top