using System.Collections.Generic;
public static void Main()
List<Student> students = new List<Student>()
new Student(){ Id=1 ,Name="Pratik", Age=24, subjects=new List<string>(){"s1", "s2"}},
new Student(){ Id=2, Name="Ashish", Age=28, subjects=new List<string>{"s1", "s4"}},
new Student(){ Id=3, Name="Umesh", Age=24, subjects=new List<string>(){"s1" }},
new Student(){ Id=4, Name="Ajay", Age=28, subjects=new List<string>(){"s5", "s1"}},
new Student(){ Id=5, Name="Vijay", Age=24, subjects=new List<string>(){"s1"}},
new Student(){ Id=6, Name="Shital", Age=24, subjects=new List<string>(){"s2", "s3"}}
var data = students.SelectMany(p => p.subjects.Select(s => new { p.Name, Subject = s }));
var result = data.GroupBy(p => p.Subject)
Names = string.Join(",", g.Select(n => n.Name))
foreach(var item in result)
Console.WriteLine(item.Key + " " + item.Names);
public Int32 Id { get; set; }
public string Name { get; set; }
public Int32 Age { get; set; }
public List<string> subjects { get; set; }