spe*_*yck 11
这将起作用:
char hLow = 'h';
char hHigh = 'H';
char.IsLower(hLow); //returns true
char.IsUpper(hHigh); //returns true
Run Code Online (Sandbox Code Playgroud)
这也可以(但这是一种相当老式的方法,并且不适用于重音字母):
(hLow >= 'a' && hLow <= 'z'); //returns true
(hHigh >= 'A' && hHigh <= 'Z'); //returns true
Run Code Online (Sandbox Code Playgroud)
另外,如果你想检查 a 中的所有字符是否string都是大写/小写,你可以这样做:
string word = "UPPERCASE";
word.All(char.IsUpper); //returns true
word.All(char.IsLower); //returns false
Run Code Online (Sandbox Code Playgroud)
请记住,您需要using System.Linq;在代码的开头添加此内容才能正常工作。
如果你想检查 a 是否string只包含字母,只需使用这个(仍然使用Linq):
word.All(char.IsLetter); //returns true
Run Code Online (Sandbox Code Playgroud)
还有更多类似的有用功能,Linq您可以在其中找到自己。