Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Customer
- {
- public int CustomerId { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public int? CustomerTypeId { get; set; }
- public string EmailAddress { get; set; }
- }
- public class CustomerRepository
- {
- public Customer Find(List<Customer> customerList, int customerId)
- {
- Customer foundCustomer = null;
- //foreach (var c in customerList)
- //{
- // if (c.CustomerId == customerId)
- // {
- // foundCustomer = c;
- // break;
- // }
- //}
- ////Provides an IENumerable to a interaction
- //var query = from c in customerList
- // where c.CustomerId == customerId
- // select c;
- //foundCustomer = query.First();
- //FirstOrDefault is a func delagate, A Func delegate defines a function that takes any number of parameters and returns a value of the
- //type specified in the last parameter.
- foundCustomer = customerList.FirstOrDefault(c =>
- c.CustomerId == customerId);
- //foundCustomer = customerList.FirstOrDefault(c =>
- // {
- // Debug.WriteLine(c.LastName);
- // return c.CustomerId == customerId;
- // });
- //foundCustomer = customerList.Where(c =>
- // c.CustomerId == customerId)
- // .Skip(1)
- // .FirstOrDefault();
- //foundCustomer = customerList.Where(c =>
- // c.CustomerId == customerId)
- // .Skip(1)
- // .FirstOrDefault();
- return foundCustomer;
- }
- public List<Customer> Retrieve()
- {
- List<Customer> custList = new List<Customer>
- {new Customer()
- { CustomerId = 1,
- FirstName="Frodo",
- LastName = "Baggins",
- EmailAddress = "fb@hob.me",
- CustomerTypeId=1},
- new Customer()
- { CustomerId = 2,
- FirstName="Bilbo",
- LastName = "Baggins",
- EmailAddress = "bb@hob.me",
- CustomerTypeId=null},
- new Customer()
- { CustomerId = 3,
- FirstName="Samwise",
- LastName = "Gamgee",
- EmailAddress = "sg@hob.me",
- CustomerTypeId=1},
- new Customer()
- { CustomerId = 4,
- FirstName="Rosie",
- LastName = "Cotton",
- EmailAddress = "rc@hob.me",
- CustomerTypeId=2}};
- return custList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement