using System;
class IsBlankOrEmpty
{
public static bool IsBlankOrEmptyMethod(string str) {
// Check for null or empty string
if (string.IsNullOrEmpty(str)) {
return true;
}
// Check if the string contains only whitespace
foreach (char ch in str) {
if (!char.IsWhiteSpace(ch)) {
return false; // Found a non-whitespace character
}
}
return true;
}
static void Main()
{
string test1 = null;
string test2 = "";
string test3 = " ";
string test4 = "abc";
Console.WriteLine("Test1: " + IsBlankOrEmptyMethod(test1));
Console.WriteLine("Test2: " + IsBlankOrEmptyMethod(test2));
Console.WriteLine("Test3: " + IsBlankOrEmptyMethod(test3));
Console.WriteLine("Test4: " + IsBlankOrEmptyMethod(test4));
}
}
/*
run:
Test1: True
Test2: True
Test3: True
Test4: False
*/