(转)c#中判断是不是数字和字母

一、判断字母
string str = Console.ReadLine();
if (char.isLetter(str))
{

}
else if (char.IsDigit(str))
{

}
if(ch>='a'&&ch<='z') 小写字母
if(ch>='A'&&ch<='Z') 大写字母
数字也一样。

判断汉字一般是输入 >255 因为汉字是大字符集

二、判断输入的是不是数字
try
{
int n = 0;
n = int.Parse(this.textBox1.Text.Trim());
}
catch
{
MessageBox.Show("你输入的不是数字~!");
}

也可以用Char.isNumber(str[i])一个一个字符判断。
原文地址:https://www.cnblogs.com/hongjiumu/p/3163296.html