Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Search item(s) in a generic list
WhatsApp
Anh Duc Thai
18y
10.7
k
0
0
25
Blog
Most often, we do with List
and find one or more items in list. Imagine that we want to look for a product in List
using PrimaryKey. The code is: foreach (Product p in this.Products) { if (p.PrimaryKey == primaryKey) return p; } We also have another way that makes it better in performance as well as readability. Predicate
condition = delegate(Product p) { return p.PrimaryKey.Equals(primaryKey); }; return this.Products.Find(condition); To find all items: this.Products.FindAll(condition); Both of them return NULL if not found.
People also reading
Membership not found