0

I have a class named Book with a property of String :

 private string? _bookName;

         public string? BookName

        {
        get
        {
            return _bookName;
        }
        set
        {
      
            _bookName = value;
        }
    }

and I created an instance of it in main and I can loop the items , but my problem is I don't want to user be able to add INT for this property , how can I prevent that?

        List<Book> books = new();
   
                Book firstBook = new()
    {
        BookName = Console.ReadLine(),
    };
    
     books.Add(firstBook);

    foreach (Book bookList in books)
    {
        Console.WriteLine
            (
            $"The Name Of The Book Is : {bookList.BookName} , " 
            )
    }

now the user can insert number as book name , how do I fix that? thanks

behnami454
  • 77
  • 8
  • Are you just asking how to check if a string has only numeric characters? – David Apr 21 '23 at 18:16
  • 1
    After you ReadLine from the console you would do a check if it is an INT you can do this a few ways, RegEx works. Then if it is an INT just show error and have them reenter. – Brad Apr 21 '23 at 18:19

0 Answers0