Finding a match in List<T>

I have a object O which has four properties a, b, c and d, I have a list List<T>.
I need to find the match in List<T> which matches the values of a and b in Object O

The object O could have a match in List<T>, but not always.
Trying to do this in linq, or whichever is most effective from a performance point.
List<T> could have around 1000 records.
LVL 1
countrymeisterAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Minh Võ CôngConnect With a Mentor Commented:
You can delegate a function to find item like:
http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Use the Find with prediacte functionality of a List eg.

List<T> sublist = masterlist.FindAll(foo);


private static bool foo(T obj)
{
//  return true if this is an object you require else return false
}
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I'm a touch surprised at the choice you made.
The comment by minhvc is effectively a copy of my comment but differing in one important aspect.  That only returns one item at most, as you wanted to select on a subset of the properties I thought the FindAll would be rather more suitable which returns more than one item if there were multiple matches in the list.  Of course for just one match or none the return results of both methods would be the same.
0
All Courses

From novice to tech pro — start learning today.