EN
C# / .NET - check if string is empty
0 points
In this article, we would like to show you how to check if string is null or empty in C#.
Quick solution:
xxxxxxxxxx
1
string string1 = "";
2
string string2 = null;
3
string string3 = "ABC";
4
5
Console.WriteLine(String.IsNullOrEmpty(string1)); // True
6
Console.WriteLine(String.IsNullOrEmpty(string2)); // True
7
Console.WriteLine(String.IsNullOrEmpty(string3)); // False
In this section, we present a full example of using IsNullOrEmpty()
method to check if strings are empty.
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
string string1 = "";
8
string string2 = null;
9
string string3 = "ABC";
10
11
Console.WriteLine(String.IsNullOrEmpty(string1)); // True
12
Console.WriteLine(String.IsNullOrEmpty(string2)); // True
13
Console.WriteLine(String.IsNullOrEmpty(string3)); // False
14
}
15
}
Output:
xxxxxxxxxx
1
True
2
True
3
False