#26 – Null Literal

The keyword null represents a null literal.  A null value indicates that a reference points to no object.

Examples:

 object o1 = null;
 if (o1 == null) Console.WriteLine("Yup, it's null");

 string s1 = null;    // Strings can also be null
 int n1 = s1.Length;  // Throws NullReferenceException, since s1 doesn't point to anything
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 Responses to #26 – Null Literal

  1. kai zhou says:

    String.IsNullOrEmpty() is quite useful, if I’m not wrong on the function name.

  2. kai zhou says:

    object.ReferenceEqual(obj, null) is also useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: