Monday , 1 May 2017
Home » Code You Should Not Be Writing – Part 4

Code You Should Not Be Writing – Part 4

This is a special Christmas Eve “Code You Should Not Be Writing” post that I think is special enough to flip over your chair.

This is a common mistake C# developers make, which is forgiveable. You should use string.IsNullOrEmpty() method instead, which was introduced only in .NET Framework 2.0. It is understandable that most developers haven’t gotten up to speed yet.

[sourcecode language=”csharp”] string duration;
// … some code assignment for duration
if (duration == string.Empty || duration == null)
// … some error handling code

But this just blew my mind. Can anyone guess why this is so very wrong?

[sourcecode language=”csharp”] string finalTitle;
// … some code assignment for finalTitle
if (finalTitle == string.Empty == null)
// … some error handling code

Yes. You should never write code like this. Heaven’s me, this is valid code! The condition is just WRONG.

Merry Christmas everyone, and I hope you like this edition of “Code You Should Not Be Writing”.

About Justin Lee

Check Also

Samsung Galaxy Note7 – “Eye-ing” the Next Evolution in the Galaxy Note Series

The next generation Samsung Galaxy Note7 combines both style and innovative features and top of …


  1. Which school is he from?
    .-= DK´s last blog ..Christmas Don’t Be Late =-.

Leave a Reply