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
.
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
.
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);
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);
List<RssFeedDocument> filteredList = listOfRssFeedDocument.Find(delegate(RssFeedDocument d) { return d.FeedId = x; });
Reference: List<T>
.Find
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; });