Advertisement
monaliza86

InvoiceList Class

Feb 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Indexers
  8. {
  9.     public class InvoiceList
  10.     {
  11.         private List<Invoice> invoices;
  12.  
  13.         public InvoiceList()
  14.         {
  15.             invoices = new List<Invoice>();
  16.         }
  17.  
  18.         public void Add(Invoice invoice)
  19.         {
  20.             invoices.Add(invoice);
  21.         }
  22.  
  23.         public void Add(string number, string description, int quantity, decimal price)
  24.         {
  25.             Invoice i = new Invoice(number, description, quantity, price);
  26.             invoices.Add(i);
  27.         }
  28.  
  29.         public void Remove(Invoice invoice)
  30.         {
  31.             invoices.Remove(invoice);
  32.         }
  33.  
  34.         public void Remove(int i)
  35.         {
  36.            invoices.RemoveAt(i);
  37.         }
  38.         public Invoice this[int i]
  39.         {
  40.        
  41.             get
  42.             {
  43.                 if (i < 0 || i > invoices.Count)
  44.                 {
  45.                     throw new ArgumentException("Invalid index");
  46.                 }
  47.                 return invoices[i];
  48.             }
  49.  
  50.             set { invoices[i] = value; }
  51.         }
  52.  
  53.         public Invoice this[string desc]
  54.         {
  55.             get
  56.             {
  57.                 foreach (Invoice invoice in invoices)
  58.                 {
  59.                     if (invoice.Description.Equals(desc))
  60.                     {
  61.                         return invoice;
  62.                     }
  63.                 }
  64.  
  65.                 return null;
  66.  
  67.             }
  68.  
  69.  
  70.         }
  71.  
  72.  
  73.     }
  74.  
  75.    
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement