views:

460

answers:

4
class Cache
{
    int sizeOfCache;//no of RssFeedDocument 
    private List<RssFeedDocument> listOfRssFeedDocument = null;
}

i want to find a object in this generic list in class based upon RssFeedDocument 's property FeedId.

+2  A: 

Assuming you can use the IEnumerable<T> extension methods, I think the easiest way is actually to use Where:

listOfRssFeedDocument.Where(doc => doc.FeedId == someId);
John Feminella
+3  A: 

Using anonymous delegate:

Guid feedID = ...;
RssFeedDocument document = listOfRssFeedDocuments.Find(
    delegate(RssFeedDocument rfd)
    { return rfd.FeedId == feedID; });

The same, but with C# 3.0 lambdas:

Guid feedID = ...;
RssFeedDocument document = 
    listOfRssFeedDocuments.Find(rfd => rfd.FeedId == feedID);
Anton Gogolev
A: 
List<RssFeedDocument> filteredList = listOfRssFeedDocument.Find(delegate(RssFeedDocument d) { return d.FeedId = x; });

Reference: List<T>.Find

Kirtan
A: 

If you aren't able to use LINQ you could use something along the lines of:

RssFeedDocument fd = ListName.Find(delegate(RssFeedDocument doc) { return doc.FeedID == someVariable; });
Dave_Stott