String.IsNullOrEmpty Method (String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Indicates whether the specified string is null or an Empty string.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member IsNullOrEmpty : 
        value:string -> bool

Parameters

value
Type: System.String

The string to test.

Return Value

Type: System.Boolean

true if the value parameter is null or an empty string (""); otherwise, false.

IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is null or its value is Empty. It is equivalent to the following code:

No code example is currently available or this language may not be supported.

You can use the IsNullOrWhiteSpace method to test whether a string is null, its value is String.Empty, or it consists only of white-space characters.

A string is null if it has not been assigned a value (in C++ and Visual Basic) or if has explicitly been assigned a value of null. Although the composite formatting feature can gracefully handle a null string, as the following example shows, attempting to call one if its members throws a NullReferenceException.

No code example is currently available or this language may not be supported.

A string is empty if it is explicitly assigned an empty string ("") or String.Empty. An empty string has a Length of 0. The following example creates an empty string and displays its value and its length.

No code example is currently available or this language may not be supported.

The following example examines three strings and determines whether each string has a value, is an empty string, or is null.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: