Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Method Syntax
            var MS  = Student1.GetAllStudents().OrderBy(x => x.Branch).ToList();
            var MS1 = Student1.GetAllStudents().
                      Where(std => std.Branch.ToUpper() == "CSE").
                      OrderBy(x => x.FirstName).ToList();
            //Query Syntax
            var QS = (from std in Student1.GetAllStudents()
                      orderby std.Branch
                      select std);

            foreach (var student in MS)
            {
                Console.WriteLine(" Branch: " + student.Branch + ", Name :" + student.FirstName + " " + student.LastName);
            }

            Console.WriteLine();

            foreach (var student in MS1)
            {
                Console.WriteLine(" Branch: " + student.Branch + ", Name :" + student.FirstName + " " + student.LastName);
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Method Syntax
            var MS = Student1.GetAllStudents()
                     .OrderBy(x => x.Branch)             //first level sort
                     .ThenByDescending(y => y.FirstName) //second level sort
                     .ToList();

            foreach (var student in MS)
            {
                Console.WriteLine(student.Branch + " - " + student.FirstName);
            }
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //Using Method Syntax
            var GroupByMS = Student1.GetAllStudents().GroupBy(s => s.Branch);
            //Using Query Syntax
            IEnumerable <IGrouping <string, Student1> > GroupByQS = (from std in Student1.GetAllStudents()
                                                                     group std by std.Branch);

            //It will iterate through each groups
            foreach (var group in GroupByMS)
            {
                Console.WriteLine(group.Key + " : " + group.Count());
                //Iterate through each student of a group
                foreach (var student in group)
                {
                    Console.WriteLine("  firstName :" + student.FirstName + ", lastname :" + student.LastName + ", id: " + student.ID);
                }
            }
            Console.Read();
        }