by Dominic Zukiewicz
23. July 2008 14:23
Microsoft recently (on my birthday) released a tool to analyse coding structure and formatting. No - its not FxCop - StyleCop analyses syntactical formatting. Let me explain: Background When Microsoft released FxCop, some people cringed. I remember at my previous job when having a code review and the conversation following: Consultant: "Have you FxCop'd it?". Me: "No...." Consultant: "Hahahah - see you in 3 months!" Those days, for me anyway, have gone. I started to use it in my everyday coding and am now pleased I use it without a second thought. In my position with this com...
[More]
by Dominic Zukiewicz
3. July 2008 09:45
I don’t know about you, but when I’ve seen some string comparisons, some people use:
string text = GetStringFromDB()
if( text != string.Empty )
DoThis();
This looks good, but its actually quite a long running process, as the CLR has to compare both strings character by character. It is much better to use String.IsNullOrEmpty to cater for this, or use .Length == 0 property, as this never changes and is computed when assigned. Here is what the String.IsNullOrEmpty method looks like:
public static bool IsNullOrEmpty(string value)
{
if (value != null)
{
...
[More]