November 2008 Archives

String.IsNullOrEmpty - performance considerations, bugs

November 20, 2008

I once read that .Net's String.IsNullOrEmpty performs better, and is safer, than just checking to see if a particular string has an empty value. I.e. replace if (myString == "") or if (myString.Equals(string.Empty)) or if (myString.Length == 0) with if (String.IsNullOrEmpty(myString)). It is certainly easy to read, and points out that the string should really be checked for null value before doing anything else.

Wanting to double-check my memory before recommending this method to a colleague, I found a few very interesting blog posts that suggest to me that I should avoid its usage:

  1. DANGER ! String.IsNullOrEmpty can lead to runtime Null exceptions !!, it looks like this isn't fully explained yet. Might not be an issue in .Net 3.0/3.5 frameworks, but I'm still using .Net 2.0, so it is best to heed this warning.
  2. string.IsNullOrEmpty Samples, it seems the performance is good, but not the best. So where performance matters, go with the longest, safest version: if (myString == null || myString.Length == 0)

Starting Out with Service Broker

November 16, 2008

Problem: you have an application that needs to trigger some process via SQL Server but don't want your main process hung up waiting. So you decide to setup Service Broker in order to make an asynchronous call, with the receiving service doing your work for you. You've read all about it, and tried it out after hours, but it didn't work. What gives?

About this Archive

This page is an archive of entries from November 2008 listed from newest to oldest.

October 2008 is the previous archive.

December 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.



OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.12