|
-
Mar 5th, 2004, 05:04 AM
#1
Thread Starter
Frenzied Member
Check if a type int is assigned a value
I declare a variable:
public int left;
Sometimes it is assigned a value other times not. Obviously I want to catch times when it isn't assign to avoid errors but I can't find a way to do it I've tried:
if (left != null) {
But null can't be used with type int.
Help!
DJ
-
Mar 5th, 2004, 01:27 PM
#2
Perhaps give it a default value?
Code:
const int DefaultValueBlah = 0;
int x = DefaultValueBlah;
if (x == DefaultValueBlah) {}
-
Mar 5th, 2004, 01:48 PM
#3
Sleep mode
No need (but it's good practice), integral datatypes are set to 0 by default , string types to "" .
-
Mar 8th, 2004, 04:08 AM
#4
Thread Starter
Frenzied Member
Thing is I don't really want a default value as the variable could be set as a negative or postive number or even zero. I need to be able to tell if this variable has been assigned a value or not.
I'm thinking I might need to have a second boolean variable that holds if this value was set.
Cheers
DJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|