Console.WriteLine("Please enter your Mobile Number:");
Console.WriteLine("**Please note Mobile Number should be 10 digits only e.g 07...");
//AVOIDS EXCEPTION HANDLING OF ENTERING ANY TYPE THAT IS NOT AN INTEGER
while (!int.TryParse(Console.ReadLine(), out Option)) {
Console.WriteLine("***************************************************");
Console.WriteLine("Please Enter a valid numerical value!");
Console.WriteLine("Please Enter option 1 or option 2:");
}
答案 0 :(得分:0)
在字符串变量中读取控制台,计算长度并检查字符串是否为数字。 //代码
string mobNo = Console.ReadLine();
if(mobNo.Length == 10)
{
bool isNum = int.TryParse(mobNo);
if(isNum)
//continue code
}
//return error