Ejemplo n.º 1
0
        /*2.4 Deliver Subject CourseCode and Insructor Email*/
        protected static void InstructorEmailByCourse()
        {
            XElement myCourses           = XElement.Load("Courses.xml");                                                                                        //Load XML file in App_data
            IEnumerable <XElement> query =
                from instructor in Instructors                                                                                                                  //From each object in Instructor list.
                join course in myCourses.Elements("Course") on instructor.InstructorName.ToLower() equals(string)(course.Element("Instructor").Value).ToLower() //Join the XML and list in which the instructor name in Crourses.xml and instructors list matched.
                    where Convert.ToInt32(course.Element("CourseCode").Value) >= 200 && Convert.ToInt32(course.Element("CourseCode").Value) < 300               //Filter the result with 200 level courses
                orderby(string) course.Element("CourseCode")                                                                                                    //Sort the result by Course Code in ascending order.
                select new XElement("Course",                                                                                                                   //New Course Element
                                    new XElement("CourseCode", (string)course.Element("CourseCode")),                                                           //New CourseCode Element
                                    new XElement("Subject", (string)course.Element("Subject")),                                                                 //New Subject Element
                                    new XElement("Email", instructor.EmailAddress));                                                                            //New Email Element

            foreach (XElement IEmail in query)
            {
                Console.WriteLine("Subject CourseCode: {0}{1}, Instructor's Email: {2}", IEmail.Element("Subject").Value, IEmail.Element("CourseCode").Value, IEmail.Element("Email").Value);//Write the result to console.
            }
        }