Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Найдите любые ошибки/улучшения в следующем фрагменте кода
- using System.Collections.Generic;
- using System.Linq;
- public static class Enumerable
- {
- public class StudentAndCourse
- {
- public Student Student { get; set; }
- public Course Course { get; set; }
- }
- public class Student
- {
- public string Name { get; set; }
- public int? Course { get; set; }
- }
- public class Course
- {
- public int? CourseID { get; set; }
- public string Namе { get; set; }
- }
- public static IEnumerable<StudentAndCourse> Do(IEnumerable<Student> students, IEnumerable<Course> courses)
- {
- if (students.Count() == 0)
- return new List<StudentAndCourse>();
- var result = new List<StudentAndCourse>();
- foreach (var student in students)
- {
- result.Add(new StudentAndCourse()
- {
- Student = student,
- Course = courses.Single(d => d.CourseID == student.Course)
- });
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment