C# में IsNullOrWhiteSpace() मेथड यह इंगित करता है कि कोई निर्दिष्ट स्ट्रिंग null, खाली है, या केवल व्हाइट-स्पेस कैरेक्टर्स से बनी है।
सिंटैक्स
public static bool IsNullOrWhiteSpace (string val);
उपरोक्त, पैरामीटर val परीक्षण करने के लिए स्ट्रिंग है।
उदाहरण 1
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
उदाहरण 2
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