Cipher
10-28-2005, 01:09 PM
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; :o
Brandoe85
10-28-2005, 01:26 PM
Yes, C# doesn't allow you to use unitialized variables. Where are you setting the value of CatId? Are you trying to manipulate it before you set it? If you're setting the value within a conditional statement, it will throw that error because that condition might not always be met, so you can either initialize it, or have additional steps to set the value.
Good luck;
Cipher
10-28-2005, 02:10 PM
Well here's my Code which throws the error
int CatID;
if (Request.QueryString["Ca"] != null) {
CatID = int.Parse(Request.QueryString["Ca"]);
}
Brandoe85
10-28-2005, 02:29 PM
Yeah, it's in a conditional statement, therefore if that statement isn't met, the value of CatId will never be assigned. You can either initialize it when you declare it, or have an else clause which assigns it some value when the condition isn't met.
Good luck;
Cipher
10-28-2005, 03:27 PM
Well i tried also this and it worked
int CatID = new int();
Thanks anyway
Brandoe85
11-04-2005, 09:16 PM
Well i tried also this and it worked
int CatID = new int();
Thanks anyway
I'd just like to point out that it seems a bit unnecessary, as it's the same as:
int CatID = 0;