The following post points out several misunderstandings that can get you into some confusing situations.
More Bad Practices
1. NOT UNDERSTANDING FALSE-Y VALUES
The False-y values are:
All other values that aren’t listed in the above list will be considered truth-y (including all objects, the strings “0″, “false”, and many other strange combinations).
We will examine the implications of knowing these false-y values a little further in the next few sections.
2. NOT TESTING & SETTING DEFAULT VALUES CORRECTLY
You can easily spot a C# developer if you see them checking for null inside of an if statement or when setting a default value.
Checking for Null
It is common and considered a best practice in C# to check for null before using a variable. If you don’t, then you might fall victim to the dreaded “Object reference not set to an instance of an object” exception. Also, when dealing with strings you’ll also want to test if it is empty or not. The following code snippet is a typical way to do this in C#.