Wednesday, October 8, 2008

Null and ToString (Asp.Net)

Sometimes while using ToString method for a object we end up in a situation where object is null and we get Null Exception. eg

Object 0 = null;
o.ToString();

In this case we can use if condition to check whether the object is null and then use ToString method.

if (o != null)
{
o.ToString();
}

No comments: