
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use String.Empty to Initialize a String in C#
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!
Advertisements