Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Customers {
- /**
- * Remeber to implement the IEnumerable interface so that you can use
- * an instance of this class on a foreach.
- */
- // .......
- //The return type has to change to CoffeeType as well.
- public CoffeeType this[string sNmae]{
- /**
- * The following is fine. Not sure if you need the ToList() at the
- * end though.
- */
- //Add .Coffee at the end to return CoffeeType.
- get { return lstCustomers.Where(s => s.Name == sName).ToList()[0].Coffee; }
- /**
- * This is where you need to make some changes.
- */
- set {
- //Get collection
- var customers = lstCustomers.Where(s => s.Name == sName);
- //Check if there is anything in the collection.
- if( customers.Exists()){
- //Get first value
- var cust = customers.First();
- cust.Coffee = value;
- }
- else {
- var cust = new CCustomer(sName, value); //First Parameter is Name and second is CoffeeType.
- }
- }
- }
- // .......
- }
Add Comment
Please, Sign In to add comment