Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. myList.ForEach(p => myFunc(p));
  2.  
  3. public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
  4. {
  5. foreach(T item in source)
  6. action(item);
  7. }
  8.  
  9. myList.Where( ... ).ForEach( ... );
  10.  
  11. string[] items = (new string[] { "d", "f" }).
  12. Select(x => new Func<string>(() => {
  13. //Do something here...
  14. Console.WriteLine(x);
  15. return x.ToUpper();
  16. }
  17. )).Select(t => t.Invoke()).ToArray<string>();
  18.  
  19. var functions = (new string[] { "d", "f" }).
  20. Select(x => new Func<string>(() => {
  21. //Do something here...
  22. Console.WriteLine(x);
  23. return x.ToUpper();
  24. }));
  25. string[] items = functions.Select(t => t.Invoke()).ToArray<string>();
  26.  
  27. myList.ForEach(p => myFunc(p));
  28.  
  29. items.ForEach(item => DoSomething(item));
  30.  
  31. public class Employee
  32. {
  33. public string EmployeeNumber { get; set; }
  34. public DateTime? HireDate { get; set; }
  35. }
  36. public class EmployeeCollection : List<Employee>
  37. { }
  38.  
  39. private void RunTest()
  40. {
  41. EmployeeCollection empcoll = new EmployeeCollection();
  42. empcoll.Add(new Employee() { EmployeeNumber = "1111", HireDate = DateTime.Now });
  43. empcoll.Add(new Employee() { EmployeeNumber = "3333", HireDate = DateTime.Now });
  44. empcoll.Add(new Employee() { EmployeeNumber = "2222", HireDate = null });
  45. empcoll.Add(new Employee() { EmployeeNumber = "4444", HireDate = null });
  46.  
  47. //Here's the "money" line!
  48. empcoll.Where(x => x.HireDate.HasValue == false).ToList().ForEach(item => ReportEmployeeWithMissingHireDate(item.EmployeeNumber));
  49.  
  50. }
  51. private void ReportEmployeeWithMissingHireDate(string employeeNumber)
  52. {
  53. Console.WriteLine("We need to find a HireDate for '{0}'!", employeeNumber);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement