static class StringExtensions { public static string BracketSelf(this string instance) { return "[" + instance + "]"; } }
string s = "Text"; Console.WriteLine(s.BracketSelf()); // this should output [Text]
string s = null; Console.WriteLine(s.BracketSelf()); // this should output [] Console.WriteLine(s.ToLower()); // this should throw a NullReferenceException
static class StringExtensions { public static string BracketSelf(this string instance) { if (instance == null) throw new NullReferenceException(); return "[" + instance + "]"; } }
Al Gonzalez P.S. Solutions, Inc. http://www.linkedin.com/in/algonzalez
public static bool IsNull(this object instance) { return instance == null; }
string s = null; Console.WriteLine(s.IsNull()); // this should output true s = "Some Text"; Console.WriteLine(s.IsNull()); // this should output false
Copyright (c) 2008 GSP Developers Walling Info Systems | Terms Of Use | Privacy Statement