Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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,
Posted
Updated 18-May-12 5:27am
v2

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
 
Share this answer
 
Comments
VJ Reddy 21-May-12 13:03pm    
Good references. 5!
Sergey Alexandrovich Kryukov 21-May-12 14:08pm    
Thank you, VJ.
--SA
 
Share this answer
 
Comments
Look87 18-May-12 11:59am    
Thank you for the ref.
Sergey Alexandrovich Kryukov 18-May-12 12:17pm    
That's a good reference, but I notices that extension methods are not explained in this article. I voted 4.
I added my answer with additional link, please see.
--SA
aidin Tajadod 18-May-12 12:30pm    
my 5.
Shmuel Zang 19-May-12 16:12pm    
Thanks.
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-May-12 12:10pm    
OK, and where is "Where"? There is no such thing in the System.Collections.Generic.List<> class... do you know?
--SA
sjelen 21-May-12 10:54am    
It's an extension method, member of System.Linq.Enumerable, located in System.Core (at least in .NET 4.0, not sure about previous versions).
Sorry for late reply, I see now it's already mentioned.
Sergey Alexandrovich Kryukov 28-May-12 18:28pm    
That's correct, and that was my point -- the use of extension methods; that's why I added my answer to complement the one by Shmuel Zang; please see both...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900