C#中的Char.IsWhiteSpace()方法

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