以下の例では、を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、プロファイリングによって駆動されないマイクロ最適化。イテレータとリストへのコピーの作成は、数学をマイクロ最適化することによって行われる節約より数百倍遅くなります。 *遅いものを最適化する* –