Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public class CourseEvent : ICourseEvent
  2. {
  3. // other properties
  4. public string Vendor { get; set; }
  5. }
  6.  
  7. public class CourseVendor
  8. {
  9. public string Name { get; set; }
  10. }
  11.  
  12. // 1) get List<CourseEvent> items
  13. List<CourseEvent> courseEvents = LoadCourseEvents();
  14.  
  15. // 2) group items by property "Vendor"
  16. IEnumerable<IGrouping<string,CourseEvent>> groups = courseEvents.GroupBy(c => c.Vendor).ToList();
  17.  
  18. // 3) convert to list
  19. List<CourseEvent> courseVendors = groups.SelectMany(group => group).ToList();
  20.  
  21. // 4) initiate target class
  22. List<CourseVendor> vendors = new List<CourseVendor>();
  23.  
  24. // 5) fill target class
  25. courseVendors.ForEach(c => vendors.Add(new CourseVendor { Name = c.Vendor }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement