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.
Im assuming Visual Studio 8 here.
ReplyDelete