स्ट्रिंग का उपयोग करके स्ट्रिंग को खाली के रूप में सेट करें। C# में खाली -
string myStr = string.Empty;
यह जाँचने के लिए कि यह एक स्ट्रिंग है या नहीं, IsNullOrEmpty() विधि का उपयोग करें -
if (string.IsNullOrEmpty(myStr)) {
Console.WriteLine("String is empty or null!");
} निम्नलिखित एक उदाहरण है -
उदाहरण
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!");
}
}
}
} आउटपुट
String is empty or null!