Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Indexers
- {
- public class InvoiceList
- {
- private List<Invoice> invoices;
- public InvoiceList()
- {
- invoices = new List<Invoice>();
- }
- public void Add(Invoice invoice)
- {
- invoices.Add(invoice);
- }
- public void Add(string number, string description, int quantity, decimal price)
- {
- Invoice i = new Invoice(number, description, quantity, price);
- invoices.Add(i);
- }
- public void Remove(Invoice invoice)
- {
- invoices.Remove(invoice);
- }
- public void Remove(int i)
- {
- invoices.RemoveAt(i);
- }
- public Invoice this[int i]
- {
- get
- {
- if (i < 0 || i > invoices.Count)
- {
- throw new ArgumentException("Invalid index");
- }
- return invoices[i];
- }
- set { invoices[i] = value; }
- }
- public Invoice this[string desc]
- {
- get
- {
- foreach (Invoice invoice in invoices)
- {
- if (invoice.Description.Equals(desc))
- {
- return invoice;
- }
- }
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement