C# 标识符命名规则https://blog.csdn.net/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 + " 不是合法字符串");
}