- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IsNullOrEmpty() Method in C#
The IsNullOrEmpty() method in C# is used to indicate whether the specified string is null or an empty string ("").
Syntax
The syntax is as follows−
public static bool IsNullOrEmpty (string val);
Above, the value val is the string to test.
Example
Let us now see an example −
using System; public class Demo { public static void Main(){ string str1 = "Amit"; string str2 = " "; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); } }
Output
This will produce the following output −
Is string1 null or empty? = False Is string2 null or empty? = False
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ string str1 = null; string str2 = String.Empty; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); } }
Output
This will produce the following output −
Is string1 null or empty? = True Is string2 null or empty? = True
Advertisements
To Continue Learning Please Login
Login with Google