C# 标识符命名规则https://blog.youkuaiyun.com/qq_40985921/article/details/82975635
直接上代码
string str = Console.ReadLine();
bool isRight = true;
if ((str[0] >= 'a' && str[0] <= 'z') || (str[0] >= 'A' && str[0] <= 'Z') || str[0] == '_' || str[0] == '@')
{
}
else
{
isRight = false;
}
for (int i = 1; i < str.Length; i++)
{
if ((str[i]>='a'&& str[i] <= 'z')||(str[i]>='A'&& str[i] <= 'Z')||str[i]=='_' ||(str[i]>='0'&&str[i]<='9'))
{
}
else
{
isRight = false;
break;
}
}
if (isRight==true)
{
Console.WriteLine(str+" 是合法字符串");
}
else
{
Console.WriteLine(str + " 不是合法字符串");
}
本文介绍了一个简单的C#程序,用于验证用户输入的字符串是否符合C#标识符的命名规则。通过逐字符检查首字符及后续字符,判断字符串是否有效。
684

被折叠的 条评论
为什么被折叠?



