Welcome to fuzzydev Sign in | Join | Help
in Search

.Net

String.IsNullOrEmpty(String)

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 [;)]

Published 10 June 2006 by sachinjoshi
Filed Under:
New Comments to this post are disabled

This Blog

Post Calendar

<June 2006>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

Sponsored Links

Syndication

Copyright 2006, Sachin Joshi. All rights reserved.
The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer's in any way.
Powered by Community Server, by Telligent Systems