我有一个包含15位帐号的字符串。第一位数字不能是0、1、8或9。 我想表达的意思是:
public bool ValidateAccountNumber(string Accountnumber )
{
char[] Invalidboro = new char[] { '0', '1', '8', '9'};
bool returnValue = true;
if (Accountnumber.Length != 15 || Accountnumber.Substring(1, 1).Contains(Invalidboro))
{
returnValue = false;
}
return returnValue;
}
我是C#新手,不太确定如何做这个。
Substring(1, 1)
将获取第二个字符,因为索引从0
开始。此外,不需要returnValue
。您可以简单地使用return false;
或return true;
。您甚至可以使用return Accountnumber.Length != 15 || Invalidboro.Contains(Accountnumber[0]);
完全省略if
语句。 - 001