Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 7th, 2008, 12:45 PM
Fresno Bob
Guest
 
Posts: n/a
Default Find Method on Generic List

I have a generic collection of objects and I would like to find the object
by one of it's properties e.g. I would like something with the functionality
of something like list.find(Customer.CustomerID = 1). Is there an easy way
to do this. The stuff with predicates and findall is a little confusing.


  #2  
Old September 7th, 2008, 01:55 PM
Anthony Jones
Guest
 
Posts: n/a
Default Re: Find Method on Generic List

"Fresno Bob" <nospam@nospam.comwrote in message
news:eCCjC7NEJHA.5004@TK2MSFTNGP04.phx.gbl...
Quote:
>I have a generic collection of objects and I would like to find the object
>by one of it's properties e.g. I would like something with the
>functionality of something like list.find(Customer.CustomerID = 1). Is
>there an easy way to do this. The stuff with predicates and findall is a
>little confusing.
>
You don't state your Language or version. In C# 3:-

Customer cust = list.Find(c =c.CustomerID == 1);

In C# 2 you need to bloat the lambda to a delegate:-

Customer cust = list.Find(delegate(Customer c) { return c.CustomerID ==
1;});

I don't do VB so but the principle I'm sure is the same.

--
Anthony Jones - MVP ASP/ASP.NET

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles