在下面的示例中,如何將eventScores
輕鬆轉換爲List<int>
,以便我可以將它用作prettyPrint
的參數?如何將System.Linq.Enumerable.WhereListIterator <int>轉換爲列表<int>?
Console.WriteLine("Example of LINQ's Where:");
List<int> scores = new List<int> { 1,2,3,4,5,6,7,8 };
var evenScores = scores.Where(i => i % 2 == 0);
Action<List<int>, string> prettyPrint = (list, title) =>
{
Console.WriteLine("*** {0} ***", title);
list.ForEach(i => Console.WriteLine(i));
};
scores.ForEach(i => Console.WriteLine(i));
prettyPrint(scores, "The Scores:");
foreach (int score in evenScores) { Console.WriteLine(score); }
Pfft ,慢碼! i =>(i&1)== 0 – leppie
Pfft,微分優化不受分析驅動。迭代器的創建和複製到列表的速度將比微觀優化數學節省的成本慢數百倍。 *優化緩慢的東西* –