Actually, i am trying to group the list of students by city. When i execute this i get "Object Reference" error in LINQ statement near s2.City.
class Groupby
{
Student[] s = new Student[10];
public Groupby()
{
s[0] = new Student("Manikandan", "Jayagopi", "Chennai");
s[1] = new Student("Ganesh", "Bayyanna", "Bangalore");
s[2] = new Student("Laxman", "Bharghav", "Hyderabad");
s[3] = new Student("Dinesh","Vellaiyan","Pune");
s[4] = new Student("Natarajan","Nallathambi","Chennai");
}
public void Group()
{
var groupQuery = from s2 in s
group s2 by s2.City;
foreach (Student s1 in groupQuery)
Console.WriteLine(" {0}", s1.FirstName);
}
}
class Program
{
static void Main()
{
Groupby objGroupby = new Groupby();
objGroupby.Group();
Console.ReadLine();
}
}
Can anyone help me out?
Thanks in advance