- 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
How to use string.Empty or 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
To Continue Learning Please Login
Login with Google