女巫的做法是更好的,或什麼是這樣做的更好的辦法:Foreach循環使用LINQ語句的性能
Stuffs[] stuffs = getStuffs();
1)
foreach (var stuff in stuffs.Where(x => x.StartDate <= DateTime.Now.AddDays(-1) && x.EndDate != DateTime.MinValue))
{
}
2)
foreach (var stuff in stuffs.Where(x => x.StartDate <= DateTime.Now.AddDays(-1) && x.EndDate != DateTime.MinValue).ToList())
{
}
3)
stuffs = stuffs.Where(x => x.StartDate <= DateTime.Now.AddDays(-1) && x.EndDate != DateTime.MinValue).ToArray();
foreach (var stuff in stuffs)
{
}
我覺得數字3是獲得更好的性能。還有什麼想法?
感謝您的解釋 – 2011-05-03 06:22:11