在下面的示例中,我如何轻松转换 eventScores
至 List<int>
这样我就可以将它用作 prettyPrint
的参数?
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); }
最佳答案
您将使用 ToList 扩展:
var evenScores = scores.Where(i => i % 2 == 0).ToList();
关于c# - 如何将 System.Linq.Enumerable.WhereListIterator<int> 转换为 List<int>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1537528/