static void Main()
    {
        StudentsDirectory database1 = new StudentsDirectory();
        SpecialtiesDirectory database2 = new SpecialtiesDirectory();

        // LINQ query
        var joinedData =
                from student in database1.Students
                orderby student.FirstName ascending, student.LastName ascending
                join speciality in database2.StudentSpecialties on student.FacultyNumber equals speciality.FacultyNumber
                select new { student.FirstName, student.LastName, student.FacultyNumber, speciality.Speciality };

        // lambda expression
        var joinedDataLinqExtMtd =
            database1.Students.OrderBy(st => st.FirstName)
                .ThenBy(st => st.LastName)
                .Join(database2.StudentSpecialties, st => st.FacultyNumber, sp => sp.FacultyNumber,
                    (student, speciality) =>
                        new { student.FirstName, student.LastName, student.FacultyNumber, speciality.Speciality });

        // printing
        Console.WriteLine("{0, -18} {1, -8} {2, -12}", "Name", "FacNum", "Specialty");
        foreach (var item in joinedData)
        {
            Console.WriteLine("{0, -18} {1, -8} {2, -12}", item.FirstName + " " + item.LastName, item.FacultyNumber, item.Speciality );
        }
    }
        public static List<StudentWithGroup> CreateGroupsDirectory()
        {
            var studentsWithGroups = new List<StudentWithGroup>();

            // using the intitial students databae, to create new studets with groups database
            StudentsDirectory database = new StudentsDirectory();
            foreach (var student in database.Students)
            {
                if (student.GroupNumber == 1)
                {
                    studentsWithGroups.Add(new StudentWithGroup(student, "C#"));
                }
                else if (student.GroupNumber == 2)
                {
                    studentsWithGroups.Add(new StudentWithGroup(student, "PHP"));
                }
                else if (student.GroupNumber == 3)
                {
                    studentsWithGroups.Add(new StudentWithGroup(student, "JS"));
                }
                else if (student.GroupNumber == 4)
                {
                    studentsWithGroups.Add(new StudentWithGroup(student, "Java"));
                }
                else
                {
                    studentsWithGroups.Add(new StudentWithGroup(student, "No group chosen"));
                }
            }

            return studentsWithGroups;
        }
        public static void Main()
        {
            //  Problem 1.	Class Student - creating an instance of the StudentsDirectory class, so that we can use its List<Student> with sample students
            StudentsDirectory database = new StudentsDirectory();

            // printing
            database.Students.PrintStudentsInfo();
        }
        public static void Main()
        {
            //  Problem 1.	Class Student - creating an instance of the StudentsDirectory class, so that we can use its List<Student> with sample students
            StudentsDirectory database = new StudentsDirectory();

            // printing
            database.Students.PrintStudentsInfo();
        }
Beispiel #5
0
 static void Main(string[] args)
 {
     StudentsDirectory database = new StudentsDirectory();
     var studentsByPhone =
         from student in database.Students
         where student.Phone.StartsWith("02") || student.Phone.StartsWith("+3592")|| student.Phone.StartsWith("+359 2")
         select student;
     foreach (var student in studentsByPhone) Console.WriteLine("{0} {1}, {2}",student.FirstName, student.LastName, student.Phone);
 }
Beispiel #6
0
 static void Main(string[] args)
 {
     StudentsDirectory database = new StudentsDirectory();
     var excellentStudent =
         from student in database.Students
         where student.Marks.Contains(6)
         select student;
     foreach(var student in excellentStudent)
     Console.WriteLine("{0} {1}, {2}", student.FirstName,student.LastName,string.Join(",",student.Marks));
 }
        static void Main()
        {
            // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
            StudentsDirectory database = new StudentsDirectory();

            // running LINQ query
            var studentsByPhoneQuery = database.Students.StudentsByPhoneQuery();

            // printing - by invoking the PrintStudentsInfo() method from the StudentsByFirstAndLastName project
            StudentsByFirstAndLastName.PrintStudentsInfo(studentsByPhoneQuery);
        }
        static void Main()
        {
            // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
            StudentsDirectory database = new StudentsDirectory();

            // running LINQ query
            var studentsByNames = database.Students.StudentsByNames();

            // printing
            PrintStudentsInfo(studentsByNames);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            StudentsDirectory database = new StudentsDirectory();

            var studentsByEmail =
                from student in database.Students
                where student.Email.Substring(student.Email.Length - 6) == "abv.bg"
                select student;
            foreach (var student in studentsByEmail)
                Console.WriteLine("{0} {1}, {2}", student.FirstName, student.LastName, student.Email);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            StudentsDirectory database = new StudentsDirectory();

            var weakStudents =
                from student in database.Students
                where (student.Marks.Count(x => x == 2) == 2)
                select student;
            foreach(var student in weakStudents)
                Console.WriteLine("{0} {1}, {2}", student.FirstName, student.LastName, string.Join(",", student.Marks));
        }
        static void Main()
        {
            // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
            StudentsDirectory database = new StudentsDirectory();

            // running LINQ query
            var excellentStudents =
                from student in database.Students
                where student.Marks.Contains(6)
                select new { Fullname = string.Join(" ", student.FirstName, student.LastName), Marks = string.Join(", ", student.Marks) };

            // printing
            foreach (var student in excellentStudents)
            {
                Console.WriteLine("Name: {0}, Grades: {{{1}}}", student.Fullname, student.Marks);
            }
        }
    static void Main()
    {
        // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
        StudentsDirectory database = new StudentsDirectory();

        // using lambda expressions
        var sortedStudents =
        database.Students.OrderByDescending(student => student.FirstName).ThenBy(student => student.LastName);

        // running LINQ query
        var studentsSortQuery = database.Students.StudentsSortQuery();

        // printing - by invoking the PrintStudentsInfo() method from the StudentsByFirstAndLastName project
        StudentsByFirstAndLastName.PrintStudentsInfo(sortedStudents);
        Console.WriteLine();
        StudentsByFirstAndLastName.PrintStudentsInfo(studentsSortQuery);
    }
    static void Main()
    {
        // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
        StudentsDirectory database = new StudentsDirectory();

        // running LINQ query
        var studentsByAgeQuery =
            from student in database.Students
            where student.Age >= 18 && student.Age <= 24
            select new {student.FirstName, student.LastName, student.Age}; // limiting the query to names and age

        // printing
        foreach (var student in studentsByAgeQuery)
        {
            Console.WriteLine("Name: {0} {1}, Age: {2}",
                                student.FirstName, student.LastName, student.Age);
        }
    }
Beispiel #14
0
        static void Main(string[] args)
        {
            StudentsDirectory database = new StudentsDirectory();

            var sortedStudents =
                from student in database.Students
                orderby student.FirstName descending,
                student.LastName descending
                select student;

            var sortedStudent = database.Students.OrderByDescending(student => student.FirstName).ThenByDescending(student => student.LastName);

            Console.WriteLine("LINQ");
            foreach (var student in sortedStudent) Console.Write("{0} {1}\n",student.FirstName, student.LastName);
            Console.WriteLine();
            Console.WriteLine("Lambda");
            foreach(var student in sortedStudents) Console.Write("{0} {1}\n", student.FirstName, student.LastName);
        }
Beispiel #15
0
    static void Main()
    {
        // creating an instance of the StudentsDirectory class, so that we can use its IList<Student>
        StudentsDirectory database = new StudentsDirectory();

        // running LINQ query
        var studentsByAge =
            from student in database.Students
            orderby student.Age
            select student;

        // printing
        foreach (var student in studentsByAge)
        {
            Console.WriteLine("Name: {0} {1}, Age: {2}",
                                student.FirstName, student.LastName, student.Age);
        }
    }
 static void Main(string[] args)
 {
     StudentsDirectory database = new StudentsDirectory();
 }