Link to home
Start Free TrialLog in
Avatar of baltmann
baltmann

asked on

How to test if variable is assigned?

System.DateTime d;

How do you test if the variable d has been assigned?

What about

int i;

?

Avatar of monkesdb
monkesdb
Flag of United Kingdom of Great Britain and Northern Ireland image

eh?
as far as i understood..

int i;
....
if (i!=null) // if the variable has been assigned
{
...
}
Avatar of baltmann
baltmann

ASKER

The compile errors are:

with DateTime:

System.DateTime dt ;
if(dt != null)
...
Operator '!=' cannot be applied to operands of type 'System.DateTime' and '<null>'

with int:
int i;
if(i==null){i=0;}
...
Operator '==' cannot be applied to operands of type 'int' and '<null>'

ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial