其實我試圖按城市對學生列表進行分組。當我執行此操作時,在s2.City附近的LINQ語句中出現「對象引用」錯誤。LINQ查詢處理錯誤
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();
}
}
任何人都可以幫我嗎?
預先感謝
非常感謝Kyor!這真的幫我解決了問題! – Manikandan 2012-08-09 10:34:54