C# में IsNullOrWhiteSpace () विधि का उपयोग यह इंगित करने के लिए किया जाता है कि कोई निर्दिष्ट स्ट्रिंग रिक्त है, खाली है, या उसमें केवल व्हाइट-स्पेस वर्ण हैं।
सिंटैक्स
public static bool IsNullOrWhiteSpace (string val);
ऊपर, पैरामीटर वैल परीक्षण करने के लिए स्ट्रिंग है। आइए अब एक उदाहरण देखें -
उदाहरण
आइए अब एक उदाहरण देखें:
using System;
public class Demo {
public static void Main() {
string str1 = null;
string str2 = String.Empty;
Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Is string1 null or whitespace? = True Is string2 null or whitespace? = True
उदाहरण
आइए अब एक और उदाहरण देखें -
using System;
public class Demo {
public static void Main() {
string str1 = "\n";
string str2 = "Tim";
Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
}
} आउटपुट
Is string1 null or whitespace? = True Is string2 null or whitespace? = False