O
orekinbck
Hi There
Say I want to check if object1.Property1 is equal to a value, but
object1 could be null.
At the moment I have code like this:
if (object1 != null)
{
if (object1.Property == desiredValue)
{
//Do work here
}
}
Here is my question - Can I do this ...
if (object1 != null && object1.Property == desiredValue)
{
//Do work here
}
.... and be sure that conditions are always evaluated left to right and
the evaluation stops as soon as a condition evaluates to false ?
If I can collapse the conditions into one if statement, do you think
this is more or less elegant coding?
TIA
Bill
Say I want to check if object1.Property1 is equal to a value, but
object1 could be null.
At the moment I have code like this:
if (object1 != null)
{
if (object1.Property == desiredValue)
{
//Do work here
}
}
Here is my question - Can I do this ...
if (object1 != null && object1.Property == desiredValue)
{
//Do work here
}
.... and be sure that conditions are always evaluated left to right and
the evaluation stops as soon as a condition evaluates to false ?
If I can collapse the conditions into one if statement, do you think
this is more or less elegant coding?
TIA
Bill