Guest User

Untitled

a guest
Mar 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class Customers {
  2. /**
  3. * Remeber to implement the IEnumerable interface so that you can use
  4. * an instance of this class on a foreach.
  5. */
  6.  
  7. // .......
  8. //The return type has to change to CoffeeType as well.
  9. public CoffeeType this[string sNmae]{
  10. /**
  11. * The following is fine. Not sure if you need the ToList() at the
  12. * end though.
  13. */
  14. //Add .Coffee at the end to return CoffeeType.
  15. get { return lstCustomers.Where(s => s.Name == sName).ToList()[0].Coffee; }
  16.  
  17. /**
  18. * This is where you need to make some changes.
  19. */
  20.  
  21. set {
  22. //Get collection
  23. var customers = lstCustomers.Where(s => s.Name == sName);
  24.  
  25. //Check if there is anything in the collection.
  26. if( customers.Exists()){
  27. //Get first value
  28. var cust = customers.First();
  29. cust.Coffee = value;
  30. }
  31. else {
  32. var cust = new CCustomer(sName, value); //First Parameter is Name and second is CoffeeType.
  33. }
  34. }
  35. }
  36. // .......
  37.  
  38. }
Add Comment
Please, Sign In to add comment