using System.Collections.Generic;
public int StudentID { get; set; }
public String StudentName { get; set; }
public int Age { get; set; }
public static void Main()
IList<Student> studentList = new List<Student>()
new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
new Student() { StudentID = 2, StudentName = "Steve", Age = 15 } ,
new Student() { StudentID = 3, StudentName = "Bill", Age = 25 } ,
new Student() { StudentID = 4, StudentName = "Ram" , Age = 25 } ,
new Student() { StudentID = 5, StudentName = "Ron" , Age = 15 }
Console.WriteLine("OrderBy, ThenBy - Method Syntax\n -------------------------------" );
var result = studentList.OrderByDescending(s => s.StudentName).ThenByDescending(s => s.StudentID);
foreach (Student std in result)
Console.WriteLine(std.StudentID + " - " + std.StudentName + " - " + std.Age);
Console.WriteLine("\n orderby - Query Syntax \n------------------------ ");
var objList = from s in studentList orderby s.StudentName descending, s.StudentID descending select new {Id = s.StudentID, s.StudentName, s.Age};
foreach (Object std in objList)
Console.WriteLine("\n GroupBy - query Syntax \n ------------------------ ");
var objBY = from s in studentList group s by new {s.Age} into g select g ;
foreach(var groupby in objBY)
Console.WriteLine(groupby.Key.Age);
foreach(Student stud in groupby)
Console.WriteLine(stud.StudentID + " - " + stud.StudentName + " - " + stud.Age) ;
Console.WriteLine("\n GroupBy & OrderBy - Method Syntax \n --------------------------------");
.GroupBy(item => new {item.Age})
.Select(item1 => new {ID = item1.Last().StudentID, StudentName = item1.Last().StudentName, Age = item1.Last().Age})
.OrderBy(item2 => item2.ID).ThenBy(item3 => item3.StudentName);
foreach(var groupby in methGB)
Console.WriteLine(groupby);
Console.WriteLine("\n ToLookUp - Method Syntax \n -------------------------");
var lookup = studentList.ToLookup(item => item.Age);
foreach(var groupby in lookup)
Console.WriteLine(groupby.Key);
foreach(Student stud in groupby)
Console.WriteLine(stud.StudentID + " - " + stud.StudentName + " - " + stud.Age) ;