Introduction : In this tutorial we will see how to check the string is null or empty string or not using IsNullOrEmpty() mthod of string class in .NET Framwork with C# and VB.NET code example
IsNullOrEmpty() mthod is one of the important method of string class and frequently used among the programmer to check the string is null or empty.
IsNullOrEmpty() will return Boolean value true if the given string is null or empty string.
C# Sample code sampleusing System;
namespace DotNetSpark.Tutorials
{
class DotNetSpark
{
static void Main(string[] args)
{
// Declare string
string strValue = "DotNetSpark";
// Check the given string is null or empty or not
bool result = string.IsNullOrEmpty(strValue);
// Display result
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Output:
False
VB.NET Sample example
Namespace DotNetSpark.Tutorials
Class DotNetSpark
Private Shared Sub Main(args As String())
' Declare string
Dim strValue As String = "DotNetSpark"
' Check the given string is null or empty or not
Dim result As Boolean = String.IsNullOrEmpty(strValue)
' Display result
Console.WriteLine(result)
Console.ReadLine()
End Sub
End Class
End Namespace
Output:
False |