Windows Phone Developers

Wednesday, January 7, 2009

Check if a String has Value using IsNullOrEmpty method

Check if a String has Value using IsNullOrEmpty method

IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is nullNothingnullptra null reference (Nothing in Visual Basic) or its value is Empty.

Unlike the usual way to check twice (once for null and next for empty string), this method does it in a single check

private void CheckValue()

{

String s1 = null ;

String s2 = "";

if (String.IsNullOrEmpty(s1) == true)

{

MessageBox.Show("String does not hold any text");

}

}

This method actually checks if the Value is null or if the length of the string is Zero.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment: