Set the string as empty using the string.Empty in C# −
string myStr = string.Empty;
To check whether it is a string or not, use the IsNullOrEmpty() method −
if (string.IsNullOrEmpty(myStr)) {
Console.WriteLine("String is empty or null!");
}The following is an example −
Example
using System;
namespace Demo {
public class Program {
public static void Main(string[] args) {
string myStr = string.Empty;
if (string.IsNullOrEmpty(myStr)) {
Console.WriteLine("String is empty or null!");
} else {
Console.WriteLine("String isn't empty or null!");
}
}
}
}Output
String is empty or null!