Skip to content

A Better Safe String

May 4, 2012

public static string ToSafeString(this object obj)

{

return (obj ?? string.Empty).ToString();

}

Advertisements
2 Comments leave one →
  1. May 15, 2012 9:36 pm

    I definitely love double question mark operator!

  2. December 8, 2013 11:43 am

    It comes in handy. Its properly referred to as ‘null coalesce’.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: