public static void Main()
        {
            List <StudentSpecialty> listOfSpecialties = new List <StudentSpecialty>();
            List <Student>          listOfStudents    = new List <Student>();

            string input = Console.ReadLine();

            while (input != "Students:")
            {
                var inputArgs = input.Split();

                var current = new StudentSpecialty
                {
                    SpecialtyName = inputArgs[0] + " " + inputArgs[1],
                    FacultyNumber = int.Parse(inputArgs[2])
                };
                listOfSpecialties.Add(current);

                input = Console.ReadLine();
            }

            string input2 = Console.ReadLine();

            while (input2 != "END")
            {
                var input2Args = input2.Split();

                var current = new Student
                {
                    FacultyNumber = int.Parse(input2Args[0]),
                    StudentName   = input2Args[1] + " " + input2Args[2],
                };

                listOfStudents.Add(current);
                input2 = Console.ReadLine();
            }


            var result = listOfStudents.Join(listOfSpecialties, student => student.FacultyNumber, specialty => specialty.FacultyNumber, (student, specialty) => new { student.StudentName, student.FacultyNumber, specialty.SpecialtyName }).OrderBy(student => student.StudentName);

            foreach (var item in result)
            {
                Console.WriteLine($"{item.StudentName} {item.FacultyNumber} {item.SpecialtyName}");
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var input       = Console.ReadLine();
            var students    = new List <Student>();
            var specialties = new List <StudentSpecialty>();

            while (input != "Students:")
            {
                var arr              = input.Trim().Split();
                var specialty        = arr[0] + " " + arr[1];
                var facNumber        = int.Parse(arr[2]);
                var studentSpecialty = new StudentSpecialty()
                {
                    FacultyNumber = facNumber,
                    SpecialtyName = specialty
                };
                specialties.Add(studentSpecialty);
                input = Console.ReadLine();
            }
            input = Console.ReadLine();
            while (input != "END")
            {
                var arr         = input.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var studentName = arr[1] + " " + arr[2];
                var facNumber   = int.Parse(arr[0]);
                var student     = new Student()
                {
                    FacultyNumber = facNumber,
                    Name          = studentName
                };
                students.Add(student);
                input = Console.ReadLine();
            }
            students.Join(specialties,
                          a => a.FacultyNumber,
                          b => b.FacultyNumber,
                          (a, b) => new { a.Name, a.FacultyNumber, b.SpecialtyName }
                          ).OrderBy(student => student.Name).ToList().ForEach(x => Console.WriteLine($"{x.Name} {x.FacultyNumber} {x.SpecialtyName}"));
        }