在列表中使用where方法时会发生什么情况? [英] what is happening in the where method when use over the list?

查看:103
本文介绍了在列表中使用where方法时会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串对象列表,例如List<string> myList =new List<string>();,它包含"Rob","Look","Joe"等.我在myList对象上使用Where方法,条件是每个项目的长度不大于3,然后返回它们.

我的问题是在列表对象上使用where方法时发生了什么.

希望这个问题不是那么幼稚.无论如何,还是谢谢你,

I have a list of string objects like List<string> myList =new List<string>(); and it contains "Rob", "Look", "Joe" and so on. I use Where method over the myList object using the condition where the length of the each item is not greater than 3 and return those.

My question is what happened when use the where method over the list object.

Hope the question is no so naive. Thanks anyway,

推荐答案

Shmuel Zang提供了很好的参考,但是参考文章没有解释扩展方法的工作原理,这就是密钥:
它如何工作在C#中? -第3部分(详细介绍了C#Linq) [ http://msdn.microsoft.com/en-us/library/bb383977.aspx [ ^ ].

—SA
Shmuel Zang provided a good reference, but the reference article did not explain how extension methods work, and this is the key:
How does it work in C#? - Part 3 (C# Linq in detail)[^].

Please read this:
http://msdn.microsoft.com/en-us/library/bb383977.aspx[^].

—SA


请尝试以下cp文章:

Try this cp article:


在这种情况下,列表中的每个对象传递给.Where()方法提供的谓词.如果谓词评估为"true",则将对象添加到结果列表中,最后将该列表返回到您的代码中.
What happens in this case is that each object in the list is passed to predicate supplied in .Where() method. If predicate evaluates to ''true'' object is added to result list, and finally that list is returned to your code.


这篇关于在列表中使用where方法时会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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