没有从列表中得到任何结果 [英] not getting any result from the list

查看:67
本文介绍了没有从列表中得到任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我列出了一些项目,例如"codeproject","stackoverflow","msdn".我使用Where过滤列表,并分配给以下变量,

Hello All,

I have list with few items such as "codeproject", "stackoverflow", "msdn". I filter the list using Where and assign to a variable as below,

var output= list.Where(i=>i.Length>5);



但输出中没有任何内容.

我想不通,请帮助我.



but there is nothing in the output.

I cannt figured out, please help me.

推荐答案

我确定它在那里;您只是由于某种原因而看不到它.这将显示一些输出:
I''m sure it''s there; you only failed to see it by some reason. This will show some output:
string[]
using System.Linq;

//...

list = new string[] {
    "CodeProject", "StackOverflow", "MSDN", "Google", "Bing", "Yahoo", };
var output = list.Where(i => i.Length > 5);
foreach (var item in output)
    System.Console.WriteLine(item);


如预期的那样,在输出上您将看到:


As expected, on output you will see:

CodeProject
StackOverflow
Google


如果将list设为类型为System.Collection.Generic.List<string>的列表,则可以看到相同的内容.尝试什么? :-)

—SA


You can see the same if you make list a list of the type System.Collection.Generic.List<string>. What to try? :-)

—SA


在此阶段,输出没有任何内容,因为您尚未实际计算该表达式.您要做的只是创建一个查询表达式.在尝试执行FirstTakeCount等操作之前,不会得到任何输出.
There is nothing in the output at this stage because you haven''t actually evaluated the expression. All you''ve done is create a query expression. You don''t get any output from it until you attempt to do something like a First or Take or Count, etc...


由于延迟执行 [在何处选择 [
because of Deferred Execution[^] and Where and Select[^]

Hope it helps :)


这篇关于没有从列表中得到任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆