这是对旧问题的跟进.
给定一个ISBN号,例如3-528-03851-5,如果传入的字符串与格式X-XXX-XXXXX-X不匹配,我应该提出哪种例外类型?
此代码验证 ISBN 是否有效。对于九位数字输入,我想通过计算和附加校验位来形成有效的 ISBN。对于少于九位数的输入,我希望它返回错误消息“请输入正确的数字”。我该怎么办?
public class isbn
{ //attributes
private string isbnNum;
//method
public string GetIsbn()
{
return this.isbnNum;
}
//constructor
public isbn()
{
Console.Write("Enter Your ISBN Number: ");
this.isbnNum = Console.ReadLine();
}//end default constructor
//method
public string displayISBN()
{
return this.GetIsbn();
}
public static void Main(string[] args)
{
//create a new instance of the ISBN/book class
isbn myFavoriteBook = new isbn();
//contains the method for checking validity
bool isValid = CheckDigit.CheckIsbn(myFavoriteBook.GetIsbn());
//print out the results of the validity.
Console.WriteLine(string.Format("Your …Run Code Online (Sandbox Code Playgroud)