本文介绍了如何System.Linq.Enumerable.WhereListIterator&LT转换,诠释>列出< INT&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的例子中,我怎么能轻易转换 eventScores 列表< INT> ,这样我可以使用它作为 prettyPrint



参数

  Console.WriteLine(示例LINQ的公司在哪里:); 
名单,LT; INT>分数=新的List< INT> {1,2,3,4,5,6,7,8};
变种evenScores = scores.Where(ⅰ= I标记%2 == 0);

动作<名单,LT; INT>中串> prettyPrint =(列表标题)=>
{
Console.WriteLine(*** {0} ***称号);
list.ForEach(ⅰ= GT; Console.WriteLine(ⅰ));
};

scores.ForEach(ⅰ= GT; Console.WriteLine(ⅰ));
prettyPrint(成绩的成绩:);
的foreach(在evenScores INT得分){Console.WriteLine(分); }


解决方案

您最好使用了ToList扩展:

  VAR evenScores = scores.Where(I = I标记%2 == 0).ToList(); 


In the below example, how can I easily convert eventScores to List<int> so that I can use it as a parameter for 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); }
解决方案

You'd use the ToList extension:

var evenScores = scores.Where(i => i % 2 == 0).ToList();

这篇关于如何System.Linq.Enumerable.WhereListIterator&LT转换,诠释&GT;列出&LT; INT&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:38