Short circuits and testing for nulls

While going through some code at my new job, I came across the following line of code:

if(productGroups.Count > 0 && productGroups != null)

This new job should be very interesting...

Published Tuesday, August 23, 2005 11:31 AM by trumpi
Filed under: ,

Comments

# re: Short circuits and testing for nulls

At least the bloke was using the conditional logic operators. Pity about the order though. -chuckle-

Tuesday, August 23, 2005 12:06 PM by Craig Nicholson

# re: Short circuits and testing for nulls

Well, just think how much you'll be able to contribute :-)

Tuesday, August 23, 2005 1:56 PM by Cathryn

# re: Short circuits and testing for nulls

Check the order of your thingies in the IF statement. If it's null the code will fall over.

Tuesday, August 23, 2005 2:27 PM by Simon Stewart

# re: Short circuits and testing for nulls

Well done Simon! You have won an ice-cream.

Tuesday, August 23, 2005 2:55 PM by Trevor Green

# re: Short circuits and testing for nulls

Yup, I found a few of these in some validation code I took over. Exactly the same but for string checking. This project should be fun, too.

"You have won an ice-cream" - lol.

Friday, August 26, 2005 8:40 AM by Hilton Giesenow