Exemplo n.º 1
0
 public void PrintAvailableItems()
 {
   Console.WriteLine("Items that can be checked out: ");
   for (int i = 0; i < Checkouts.Count; i++)
   {
     ICheckoutable item = Checkouts[i];
     if (item is Book)
     {
       Book book = (Book)item;//explicit type casting (force after checking w/ is)
       Console.WriteLine($"{i + 1}. Type={book.PubType}: {book.Title} -- {book.Author} ");
     }
     Magazine newMag = item as Magazine;//implicit type casting, try and check for null
     if (newMag != null)
     {
       Console.WriteLine($"{i + 1}. Type={newMag.PubType}: {newMag.Title} -- {newMag.Volume} ");
     }
   }
 }//end of printavailabeitems
Exemplo n.º 2
0
 //helper methods
 public void AddMag(Magazine newMag)
 {
   Magazines.Add(newMag);
 }