Monday , 24 April 2017
Home » Code You Should Not Be Writing – Part 3

Code You Should Not Be Writing – Part 3

Well, this is part 3 already. I hope you’ve enjoyed and appreciated the last 2 part and understand my pain. Well, here’s something that doesn’t seem all too convoluted, but could have been achieved with just 1 line of code. By the way, just for those who don’t know, there isn’t really anything syntactically wrong with any of these code.

[sourcecode language=”csharp”] for (int i = 0; i < 24; i++)
string strIndex;
if (i < 10)
strIndex = "0" + i.ToString();
strIndex = i.ToString();
// … do more stuff with strIndex

It’s slightly tougher to understand why this is bad code for those inexperienced. For those you understand why you should not write this code, good for you! You’ve got some developer sense in you. Till the next part, I hope you enjoy this code. Learn not to write like that, please.

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. guess the Pad methods are still quite obscure.

  2. How you shorten to 1 line? I can only shorten to 3.

  3. strIndex = string.Format(“{0:00}”, i);

    Or any other languages with a format string method.

Leave a Reply