C# 中的 Char.IsLetterOrDigit() 方法

csharpserver side programmingprogramming更新于 2025/9/18 16:24:00

C# 中的 Char.IsLetterOrDigit() 方法指示指定的 Unicode 字符是属于字母还是十进制数字。

语法

以下是语法 −

public static bool IsLetterOrDigit (char ch);

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

示例

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

using System;
public class Demo {
   public static void Main(){
      bool res;
      char val = '1';
      Console.WriteLine("Value = "+val);
      res = Char.IsLetterOrDigit(val);
      Console.WriteLine("Is the value a letter or digit? = "+res);
   }
}

输出

这将产生以下输出 −

Value = 1
Is the value a letter or digit? = True

示例

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

using System;
public class Demo {
   public static void Main(){
      bool res;
      char val = '$';
      Console.WriteLine("Value = "+val);
      res = Char.IsLetterOrDigit(val);
      Console.WriteLine("Is the value a letter or digit? = "+res);
   }
}

输出

这将产生以下输出 −

Value = $
Is the value a letter or digit? = False

相关文章