1
使用LINQ,如何將此列表結果分組爲firstThree?我的組方法不起作用。LINQ - GROUP BY IEnumerable
var findOtherZipCodes = (from z in zipCodes
from results in zipFirstThree
where (results.region.ToUpper() == z.City
&& results.state == z.State)
select new ZipCodeFirstThree
{
region = z.City,
state = z.State,
firstThree = z.ZipCode1.ToString().Substring(0, 3),
zipCode = z.ZipCode1.ToString()
}).ToList();
findOtherZipCodes.GroupBy(x => x.firstThree).ToList();
foreach (var item in findOtherZipCodes) {
Console.WriteLine(item.region + " " + item.firstThree + " " + item.zipCode);
Thread.Sleep(500);
}
的呼叫都爲'ToList'在你的代碼完成什麼。您根本不需要使用該方法來執行此查詢。 – Servy 2014-10-06 19:48:45