//The following results in a "object not set to an instance of an object error" and could occur with null data from the database: string test = null;//NOTE: String.Empty doesn't result in an error Console.WriteLine(test.Length); //The solution? Check if string is null/empty to begin with: string test = null; if (test != null && test != string.Empty) Console.WriteLine(test.Length); else Console.WriteLine(0);
Updated: Monday 8th August 2011, 09:41pm
There are 0 comments
Comments are currently closed.