using System.Collections.Generic;
public static void Main()
IList<Student> studentList = new List<Student>() {
new Student() { StudentID = 1, StudentName = "John", Age = 18, StandardID = 1 } ,
new Student() { StudentID = 2, StudentName = "Steve", Age = 21, StandardID = 1 } ,
new Student() { StudentID = 3, StudentName = "Bill", Age = 18, StandardID = 2 } ,
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20, StandardID = 2 } ,
new Student() { StudentID = 5, StudentName = "Ron" , Age = 21 }
var studentsGroupByStandard = studentList
.Where(s => s.StandardID > 0)
.GroupBy(s => s.StandardID)
.Select(sg => new { sg.Key, sg });
var studentsGroupByStandard1 = from s in studentList
group s by s.StandardID into sg
select new { sg.Key, sg };
foreach (var group in studentsGroupByStandard)
Console.WriteLine("StandardID {0}:", group.Key);
group.sg.ToList().ForEach(st => Console.WriteLine(st.StudentName ));
public int StudentID { get; set; }
public string StudentName { get; set; }
public int Age { get; set; }
public int StandardID { get; set; }