C# 中的 Char.IsWhiteSpace() 方法

csharpprogrammingserver side programming更新于 2025/9/20 7:23:00

C# 中的 Char.IsWhiteSpace() 方法用于指示指定的 Unicode 字符是否为空格。

语法

public static bool IsWhiteSpace (char ch);

上面,参数 ch 是要评估的 Unicode 字符。

现在让我们看一个实现 Char.IsWhiteSpace() 方法的示例 −

示例

using System;
public class Demo {
   public static void Main(){
      bool res;
      char val = ' ';
      Console.WriteLine("Value = "+val);
      res = Char.IsWhiteSpace(val);
      Console.WriteLine("Is the value whitespace? = "+res);
   }
}

输出

这将产生以下输出 −

Value =
Is the value whitespace? = True

现在让我们看另一个例子 −

示例

using System;
public class Demo {
   public static void Main(){
      bool res;
      char val = 'k';
      Console.WriteLine("Value = "+val);
      res = Char.IsWhiteSpace(val);
      Console.WriteLine("Is the value whitespace? = "+res);
   }
}

输出

这将产生以下输出 −

Value = k
Is the value whitespace? = False

相关文章