As simple as it gets, C# 2.0 has brought with it loads of language features. Some made a huge difference and few less talked about.
One of them is String's IsNullOrEmpty method, let's do a comparision of C# 1.1 and 2.0 logic to check for a empty and null string.
We have been doing this past several years, a condition where in we check a string object is null or empty and perform certain actions based on the the outcome of the condition.
//C# 1.1 Sample code
string sParam = null;
if( (sParam != null) && (sParam != string.Empty) ) {
//Do something
}
//C# 2.0 Sample code
string sParam = null;
if( string.IsNullOrEmpty(sParam) ) {
//Do something
}
Now the difference is pretty clear....same logic but well simplified. Many of you will be wondering why the method IsNullOrEmpty is a static member of string class. Point here is we are checking for null or empty string and if that instance of string is null then it will throw a NullReference exception.
Can the word simply be more simplied? ![Wink [;)]](/emoticons/emotion-5.gif)